What are Relations?
A relation is a connection between two tables that represents how data is associated. Relations enable you to:- Link customers to their orders
- Connect projects to team members
- Associate products with categories
- Build hierarchical data structures
- Avoid data duplication
6 Relation Types
One-to-Many, Many-to-One, Many-to-Many, and more
Bidirectional
Automatically creates inverse relationship
Lookups & Rollups
Access and aggregate linked data
V2 Performance
Enhanced junction-table architecture
Relation Types
One-to-Many (Has Many)
One record in Table A relates to many records in Table B. Example: One customer has many orders- Type:
hm(has many) - From: Customer table → Orders table
- Shows: List of related orders
Many-to-One (Belongs To)
Many records in Table A relate to one record in Table B. Example: Many orders belong to one customer- Type:
bt(belongs to) - From: Orders table → Customer table
- Shows: Single linked customer
- Inverse of: One-to-Many
Many-to-Many
Records in both tables can relate to multiple records in the other table. Example: Students and courses (students take multiple courses, courses have multiple students)- Type:
mm(many-to-many) - Junction Table: Automatically created
- Shows: List of related records
One-to-One
One record in Table A relates to exactly one record in Table B. Example: One user has one profile- Type:
oo(one-to-one) - From: Either direction
- Shows: Single linked record
- Unique: Enforces uniqueness
One-to-Many V2
Enhanced one-to-many using junction table architecture.- Type:
om(one-to-many V2) - Version: LinksVersion.V2
- Performance: Better for large datasets
- Junction Table: Uses intermediate table
Many-to-One V2
Enhanced many-to-one using junction table architecture.- Type:
mo(many-to-one V2) - Version: LinksVersion.V2
- Single Record: Returns one record despite junction table
globals.ts:79-91, LinkToAnotherRecordColumn.ts:50
Creating Relations
Select 'Links' or 'Link to Another Record'
Choose the relationship field type:
- Links: Modern V2 relationships (recommended)
- Link to Another Record: Legacy V1 relationships
Select relation type
- One-to-Many (Has Many)
- Many-to-One (Belongs To)
- Many-to-Many
- One-to-One (V2 only)
Configure relation settings
- Field Label: Name for this relationship
- Related Field Label: Name in the linked table
- Junction Table (for M2M): Auto-created or choose existing
Relationship Properties
Link Field Properties
| Property | Description | Type |
|---|---|---|
id | Unique identifier | string |
fk_column_id | Column ID | string |
type | Relation type (hm, bt, mm, oo, om, mo) | string |
fk_related_model_id | ID of linked table | string |
fk_child_column_id | Foreign key in child table | string |
fk_parent_column_id | Foreign key in parent table | string |
fk_mm_model_id | Junction table ID (M2M) | string |
fk_mm_child_column_id | Junction FK to child | string |
fk_mm_parent_column_id | Junction FK to parent | string |
virtual | Is virtual relation | boolean |
version | V1 or V2 | number |
ur | Update rule (cascade, etc.) | string |
dr | Delete rule (cascade, etc.) | string |
LinkToAnotherRecordColumn.ts:13-63
Cross-Base Relations
Relations can span across different bases:| Property | Description |
|---|---|
fk_related_base_id | Related table’s base ID |
fk_mm_base_id | Junction table’s base ID |
fk_related_source_id | Related table’s data source |
fk_mm_source_id | Junction table’s data source |
LinkToAnotherRecordColumn.ts:39-42
Working with Relations
Adding Links
In the UI:- Click the link field cell
- Search for or select records to link
- Multiple selections for Has-Many/Many-to-Many
- Single selection for Belongs-To/One-to-One
Removing Links
- Click the linked record chip
- Click the X icon to unlink
- Does not delete the related record
Managing Links Programmatically
LinkToAnotherRecordColumn.ts:72-245
Lookups
Lookups let you display a field from a linked record without duplication.What is a Lookup?
Example: Show customer name in the orders table- Requires: Link field to traverse
- Displays: Field from linked record
- Read-only: Cannot edit lookup values
- Auto-updates: When linked record changes
Creating a Lookup
Lookup Properties
Example
Column.ts:317-328
Rollups
Rollups aggregate data from linked records using functions.What is a Rollup?
Example: Total amount of all orders for a customer- Requires: Link field to traverse
- Aggregates: Values using functions
- Functions: Count, Sum, Average, Min, Max, etc.
- Auto-updates: When linked records change
Creating a Rollup
Choose aggregation function
Select how to aggregate:
- Count: Number of linked records
- Sum: Total of all values
- Average: Mean value
- Min: Smallest value
- Max: Largest value
- And more…
Rollup Functions
| Function | Description | Use Case |
|---|---|---|
count | Count linked records | Number of orders |
sum | Sum of values | Total sales amount |
avg | Average value | Average order value |
min | Minimum value | Earliest date |
max | Maximum value | Latest date |
countDistinct | Unique values count | Unique products |
sumDistinct | Sum of unique values | Unique revenue |
avgDistinct | Average of unique | Average unique price |
Rollup Properties
Example
Column.ts:330-342
Junction Tables (Many-to-Many)
Many-to-Many relations use a hidden junction table to store the relationships.What is a Junction Table?
An intermediate table that connects two tables:Junction Table Properties
- Auto-created: NocoDB creates it automatically
- Hidden: Usually hidden from UI
- Two Foreign Keys: References both related tables
- Marked as MM:
mm: trueflag
Model.ts:87-88, Model.ts:974-996
Relation Versions
V1 Relations (Legacy)
- Direct Foreign Keys: Traditional database foreign keys
- Types: Has Many, Belongs To, Many-to-Many
- Performance: Good for small datasets
V2 Relations (Modern)
- Junction Tables: All relations use intermediate tables
- Types: All relation types including One-to-Many, Many-to-One, One-to-One
- Performance: Better for large datasets
- Features: Enhanced filtering, better UI
Column.ts:346-390, UITypes.ts:481-556
Cascading Actions
Control what happens when related records are updated or deleted:Update Rules (ur)
- CASCADE: Update foreign key when parent changes
- RESTRICT: Prevent updates if children exist
- SET NULL: Set foreign key to null
Delete Rules (dr)
- CASCADE: Delete children when parent is deleted
- RESTRICT: Prevent deletion if children exist
- SET NULL: Set foreign key to null
LinkToAnotherRecordColumn.ts:46-47
Best Practices
Use V2 relations for new projects
Use V2 relations for new projects
V2 relations offer better performance and more features. Use them for all new relationships.
Name relationships clearly
Name relationships clearly
Use descriptive names: “Customer Orders” instead of just “Orders”.
Choose the right relation type
Choose the right relation type
- One-to-Many: One parent, multiple children (Customer → Orders)
- Many-to-Many: Multiple on both sides (Students ↔ Courses)
- One-to-One: Unique pairing (User → Profile)
Use lookups to avoid duplication
Use lookups to avoid duplication
Instead of copying data, use lookups to display information from linked records.
Use rollups for aggregation
Use rollups for aggregation
Summarize linked data with rollups instead of manually calculating totals.
Consider cascading carefully
Consider cascading carefully
CASCADE delete can remove many records. Use RESTRICT or SET NULL for safety.
Plan your data model
Plan your data model
Design relationships before creating tables to avoid restructuring later.
Common Patterns
One-to-Many: Customer Orders
Many-to-Many: Project Members
Hierarchical: Employee Manager
Performance Considerations
V2 relations scale better
V2 relations scale better
For large datasets with thousands of links, V2 relations perform better due to junction table indexing.
Limit lookup chains
Limit lookup chains
Deeply nested lookups (A → B → C → D) can slow queries. Limit to 2-3 levels.
Index foreign keys
Index foreign keys
Ensure foreign key columns are indexed for faster join queries.
Use rollups wisely
Use rollups wisely
Rollups calculate on every query. For very large datasets, consider caching results.
Related Resources
Fields
Learn about all field types including links
Formulas
Use formulas with linked data
Tables
Understand table structure and relationships
API Relations
Work with relations programmatically