Foreign key (1:n)
A foreign key field points from exactly one row to exactly one other row – in another table, or even in the same table (self-reference, e.g. for a page tree like in this handbook).
When creating one, you choose:
- Column name
- Target table
- Target column (must be the target table’s primary key)
The target table must be in the same data source. IllusionDB manages this relationship itself (app-managed) – it does not necessarily create a native FOREIGN KEY constraint in the database, which also works on databases that don’t support adding foreign key constraints after the fact at all (e.g. SQLite). If you instead create the column directly via SQL with a real REFERENCES constraint and sync, IllusionDB also recognizes that native foreign key relationship.
Foreign key fields are the basis for:
- Lookup fields (display a value from the target row alongside)
- Rollup fields (the reverse direction: aggregate values across all child rows)
- the parent-page field of the Wiki view (self-reference)
For relationships where one row should point to several other rows at once, a links field is the right tool instead.