baasix_create_relationship
Create relationships between collections using M2O, O2M, O2O, M2M, or M2A types. Auto-indexes foreign keys and generates junction tables to optimize query performance.
Instructions
Create a relationship between collections.
RELATIONSHIP TYPES:
M2O (Many-to-One): Creates foreign key with auto-index. products.category → categories
O2M (One-to-Many): Virtual reverse of M2O. categories.products → products
O2O (One-to-One): Creates foreign key with auto-index. user.profile → profiles
M2M (Many-to-Many): Creates junction table with auto-indexed FKs. products ↔ tags
M2A (Many-to-Any): Polymorphic junction table. comments → posts OR products
AUTO-INDEXING: All foreign key columns are automatically indexed for better query performance:
M2O/O2O: Index on the FK column (e.g., category_Id)
M2M/M2A: Indexes on both FK columns in junction tables
JUNCTION TABLES (M2M/M2A):
Auto-generated name: {source}{target}{name}_junction
Custom name: Use "through" property (max 63 chars for PostgreSQL)
Junction tables are marked with isJunction: true in schema
EXAMPLE M2O: { "name": "category", // Creates category_Id field + index "type": "M2O", "target": "categories", "alias": "products", // Reverse relation name "onDelete": "CASCADE" // CASCADE, RESTRICT, SET NULL }
EXAMPLE M2M: { "name": "tags", "type": "M2M", "target": "tags", "alias": "products" }
EXAMPLE M2M with custom junction table: { "name": "tags", "type": "M2M", "target": "tags", "alias": "products", "through": "product_tag_mapping" // Custom junction table name }
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| relationshipData | Yes | Relationship configuration | |
| sourceCollection | Yes | Source collection name |