Skip to main content
The Relationship field connects records across collections. Use it for associations such as a product on an order, the user who placed an order, or categories assigned to a post. Collections already record the user who created and last saved each record in createdBy and updatedBy; see Default fields. Set type to relationship and provide the target collection slug in relationTo:

Config options

Admin options

The admin option inherits the standard field admin options and adds settings specific to relationships:

Sort options

Provide a field name to sort every target collection the same way. Prefix it with - for descending order:
For a polymorphic field, provide a value for each collection:
Without sortOptions, the selector uses its default ordering.

Filtering relationship options

Use filterOptions to limit records in the selector and validate submitted relationships. It accepts a query constraint, or a callback that returns a constraint, true to allow every record, or false to allow none. The callback receives: The callback can return a different constraint for each target collection:

Bidirectional relationships

A Relationship field stores the connection on the record containing it. The related record does not automatically receive a reverse list. Add a Join field to the related collection when editors or API consumers need to traverse the relationship in both directions.

Stored data

The stored shape depends on whether the field accepts one or many records and one or many collection types.

Has one

A relationship to one collection stores the related record ID:
Query it through the field name:

Has one, polymorphic

An array in relationTo allows one record from any listed collection:
The value records both the collection and ID:
Query the ID through value, or query the target collection through relationTo:

Has many

Set hasMany to store an array of IDs from one collection:
Querying an ID uses the same field path:

Has many, polymorphic

Combine an array in relationTo with hasMany:
Querying the related ID uses the same .value path as a polymorphic has-one field:

Querying and filtering polymorphic relationships

Polymorphic values always identify both the target collection in relationTo and the related record in value. Their storage differs from non-polymorphic relationships, so list-view filtering is limited to the related ID. Filter by related record ID:
Or filter by target collection slug:

Linking virtual fields with relationships

A virtual field can expose data from a populated relationship without storing another database value. Set virtual to the relationship path that leads to the value.
The path starts at a relationship field on the same record. FrogBot resolves the linked value when the relationship is populated. The virtual field remains absent from database storage, so use the underlying relationship path when writing data.

Custom components

Override the field or its label through admin.components. Custom components can wrap FrogBot’s default relationship controls.

Field

Server component

Client component

Label

Server component

Client component