Composite Tables Configuration
Relevant source files
The following files were used as context for generating this wiki page:
Composite Tables Configuration in SeaORM Pro defines complex views and management interfaces that group a parent entity with its related child entities. This configuration allows the admin panel to present unified interfaces for data structures that span multiple database tables, such as a Sales Order and its associated line items and addresses.
These configurations are defined in TOML files located within the pro_admin/composite_tables/ directory and are parsed into the application's configuration at runtime to drive the UI behavior and API responses.
Sources: sea-orm-pro/src/parser.rs:34-45, pro_admin/config.toml:16
Architecture and Data Structures
The system uses a hierarchical data model to represent relationships. A CompositeTableCfg consists of exactly one parent and a vector of children.
Sources: sea-orm-pro/src/config.rs:136-141
Core Components
- ParentTableCfg: Wraps a standard table configuration and identifies it as the primary entity.
- ChildTableCfg: Uses SeaORM relation names to link related entities to the parent, inheriting standard table configuration capabilities (filtering, editing, CRUD).
- RawTableCfg: A flattened structure used by both parents and children to define table views, filters, and editor behaviors.
Sources: sea-orm-pro/src/config.rs:144-162
Configuration Relationship Diagram
The following diagram illustrates how composite configurations relate to the underlying raw table definitions.
Sources: sea-orm-pro/src/config.rs:136-162
Component Breakdown
Parent Configuration
The parent section identifies the base database table and sets the primary context for the composite view. It defines which columns appear in the main list and how the editor handles the primary record.
| Option | Type | Description |
|---|---|---|
name | String | The database table name of the parent entity. |
table.columns | List | Definition of fields to display, including titles and widths. |
editor.title_field | String | The field used as the display title in the record editor. |
editor.enable | Boolean | Whether the editor interface is active for this entity. |
| Sources: pro_admin/composite_tables/sales_order.toml:1-22, sea-orm-pro/src/config.rs:144-152 |
Children Configuration
Children are linked via SeaORM relations. Multiple children can be defined for a single parent, allowing for complex views like a customer with multiple addresses or an order with multiple details.
Sources: pro_admin/composite_tables/sales_order.toml:25-125, pro_admin/composite_tables/customer_address.toml:34-62
View and UI Customization
Configurations allow for fine-grained control over the UI, including column visibility, image rendering, and text clipping.
- Hidden Columns: Fields like
rowguidorcreated_dateare often hidden from the UI but present in the data. - Relations in Columns: A child table can display fields from a further related table (e.g., displaying
Productdetails within aSalesOrderDetaillist). - Input Types: Fields can be designated as
imagefor specialized rendering.
Sources: pro_admin/composite_tables/sales_order.toml:104-106, pro_admin/raw_tables/product.toml:16
Configuration Example: Sales Order
The following snippet demonstrates a composite table connecting a sales order to its related customer and line items.
[parent]
name = "sales_order_header"
[parent.table]
columns = [
{ title = "ID", field = "sales_order_id", width = 80 },
{ field = "order_date" },
]
[[children]]
relation = "sales_order_detail"
[children.table]
columns = [
{ field = "name", relation = "product", width = 300 },
{ field = "order_qty" },
]
Sources: pro_admin/composite_tables/sales_order.toml:1-125
Processing Logic
The ConfigParser handles the discovery and loading of these configurations.
- Discovery: The parser scans the
composite_tablesdirectory usingwalkdir. - Naming: The filename (minus extension) becomes the key for the composite table in the global configuration map.
- Deserialization: TOML content is mapped to the
CompositeTableCfgRust struct. - Integration: The resulting configurations are inserted into the
JsonCfg.composite_tablesIndexMap.
Sources: sea-orm-pro/src/parser.rs:34-45
Summary
Composite Tables Configuration enables the creation of sophisticated admin interfaces that reflect complex business relationships. By defining parent-child hierarchies in TOML, developers can configure multi-entity management views without writing custom frontend logic, relying on the project's parser to map these definitions to the admin panel's data structures.