Skip to content

Relations

Link one collection to another, so an order knows its customer and a customer knows their orders.

Real data is connected. An order belongs to a customer, a task belongs to a project, a comment belongs to a post. A relation is the field that holds that link.

Ask for one#

Describe the connection in the words you'd use out loud. You don't need to say which side holds the field.

Example message
Each order belongs to one customer. On the customer page, show their orders.

That one sentence produces both halves: a field on Orders that points at a customer, and a list on the customer page of the orders pointing back.

The two shapes#

Almost everything is one of these:

One to many. One customer has many orders. The field lives on the many side — each order points at one customer. This is the common case.

Many to many. A post has several tags, and a tag is on several posts. Neither side owns it, so the link is kept separately and both sides can show the other.

Belonging, as opposed to referring#

Within one-to-many there is a second distinction, and it changes how the records behave.

An order refers to a customer: the customer exists on their own, and would still exist if the order were deleted.

An order line belongs to its order: it has no meaning without it, and nobody would ever open a table of order lines on their own.

When a relation is a belonging, YeshBe treats the child rows as part of the parent record. In the Data tab they appear inside the parent's editor rather than in a table of their own, the link is filled in for you, and deleting the parent deletes them.

Say which it is
An order has lines. A line belongs to its order and has a product, a quantity and a price.

In the app#

A relation field shows as a record picker: a searchable list of the records it can point at, rather than a box for typing an ID. Which field is used as the label — a name, a title, an email — is picked from the collection, and you can ask for a different one.

Deleting the other side#

Deleting a customer doesn't delete their orders — it leaves those orders pointing at a record that is gone.

Next#