Real data links together: a post has an author and comments, an order has line items. A relation tells Pawabase how two tables connect, so your app can ask for both in one request instead of two. Relations don’t create foreign keys or change the table. They describe a link that already exists through an ordinary column (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

Asking for a relation the table doesn’t define is a 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:
This makes relations safe: expanding can never reveal what a direct read would hide. 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 two belongs_to links: Give post_tags a unique index on (post_id, tag_id). Then read a post’s tags through the join table:
The unique index stops the same tag being added twice.

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_many with 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.