Sub tables
Sub-table fields create one-to-many (1:M) relationships between datatables, where one parent record can have multiple child records. This is one of the most powerful features in Buzzy's datamodel, allowing you to build complex hierarchical data structures.
Overview
A sub-table field automatically manages the relationship between parent and child records using the embeddingRowID system. When you add a sub-table field to a datatable, child records are automatically linked to their parent record.
Parent Record (e.g., Restaurant Receipt)
βββ _id: "receipt_001"
βββ Restaurant: "Pizza Palace"
βββ Date: "2024-07-03"
βββ Items (Sub-table field)
βββ Item 1
β βββ _id: "item_001"
β βββ embeddingRowID: "receipt_001" β Automatic link to parent
β βββ Name: "Margherita Pizza"
β βββ Price: 18.99
βββ Item 2
βββ _id: "item_002"
βββ embeddingRowID: "receipt_001" β Automatic link to parent
βββ Name: "Caesar Salad"
βββ Price: 12.50Common Use Cases
1. Invoice and Invoice Lines
2. Project and Tasks
3. Order and Order Items
Multi-Level Hierarchies
You can create complex multi-level relationships by chaining sub-tables:
Combining Sub-tables with Linked Table Fields
Sub-tables become even more powerful when combined with Linked Table Fields:
Displaying Related Data
When displaying records that use sub-tables, you can show data from multiple levels:
Current Row Data
Fields from the current record being displayed
Child Data (Sub-table)
Records from child datatables via sub-table fields
Automatically filtered to show only children of the current record
Linked Data
Data from datatables referenced by Linked Table Fields
Product names, user details, category information, etc.
Parent/Ancestor Data
Data from parent records (via embeddingRowID)
Grandparent and great-grandparent data for breadcrumb navigation
Example: When displaying an Invoice Line, you can show:
Line details (current record)
Product name and image (linked table data)
Invoice number and customer (parent data)
Organization name (grandparent data)
Performance Considerations
Sub-tables are powerful but require careful consideration for performance:
Best Practices
Limit nesting levels: While multiple levels are supported, test performance with realistic data volumes
Use filtering: Apply filters to sub-table views to limit data retrieval
Consider data volume: Large numbers of child records may impact performance
Test with real data: Always test with production-like data volumes
Monitor query performance: Watch for slow-loading screens with complex hierarchies
When to Consider Alternatives
Very large datasets: Consider pagination or alternative data structures
Frequently accessed data: Cache commonly used data
Complex queries: Consider flattening some relationships for performance
Infrastructure Scaling
For high-performance requirements:
Upgrade your Buzzy deployment for more powerful infrastructure
Consider database optimization for large datasets
Implement caching strategies for frequently accessed data
Setup Instructions
1. Create the Parent Datatable
Design your parent datatable with appropriate fields
Consider what child data will be related
2. Create the Child Datatable
Create the child datatable with its own fields
Include any Linked Table Fields for additional relationships
3. Add Sub-table Field to Parent
In the parent datatable, add a new field
Select "Sub-table" as the field type
Configure the target datatable (child datatable)
Set appropriate permissions and display options
4. Configure Display Options
Set how child records should be displayed
Configure sorting and filtering for the sub-table
Set permissions for who can add/edit child records
Working with Sub-tables Programmatically
For detailed API examples and implementation guides for working with sub-tables programmatically, see:
REST API Documentation - Full CRUD operations for external integrations
Async API Documentation - Client-side data operations within Code Widgets
Security and Access Control
Sub-tables inherit security settings but can have additional controls:
Parent-level security: Controls access to the parent record and all children
Child-level security: Additional controls on individual child records
Field-level permissions: Control who can edit specific fields in child records
See Security and Access Control for detailed information.
Real-World Examples
Chat Application
Based on our AI-Powered Chat App:
Project Management
Related Documentation
Buzzy Datamodel Overview - Complete guide to Buzzy's datamodel
Linked Table Fields - Many-to-many relationships
Datatable to Datatable Relationships - All relationship types
Security and Access Control - Protecting your data
REST API - Programmatic data access
Async API - Code Widget integration
App Examples - Real-world implementations
Last updated