post.author_id) so expand can follow it.
Two kinds
In Studio
Open the table, choose Settings, and find Relations (Include related rows with?expand=name). Add relation asks for:
Remove relation deletes it. Existing queries that expand it start failing with a 400, so change the app first.
In your app: expand
400 (“posts has no relation ‘x’”).
Access rules still apply
Each related record is read under its own table’s rules and hides its own write-only columns. If you may read a post but not its author’s profile, the author comes back empty (null, or fewer items in a list). Check for that:
Filtering by a related record
Filter on the column that holds the link, not on the expanded object:Many-to-many
A tag system (posts have many tags, tags have many posts) uses a join table with twobelongs_to links:
Give
post_tags a unique index on (post_id, tag_id). Then read a post’s tags through the join table:
Performance and limits
- Related rows are fetched in one extra query per relation, not one per record, so expanding a list of 50 posts costs two queries, not 51.
- A
has_manywith thousands of children makes responses big. Load those separately with a filter and paging instead of expanding. - Don’t expand relations you won’t show.
In Studio: see them
Tools → Topology draws your tables and the relations between them. See Topology.Read records
Fetch with expand.
Indexes
Index the link column.