Configuration options
The ID of the related collection. This cannot be changed after the field is created.
When true, deletes the current record if all its linked relations are deleted.
Minimum number of required relation records. Set to 0 for no minimum limit.
Maximum number of relation records that can be linked. Set to 1 (or less) for single relation mode. Set to > 1 for multiple relations mode.
When true, requires at least one relation to be set.
Validation rules
The relation field validates:- Collection exists: Referenced collection must exist and be accessible
- Records exist: All referenced record IDs must exist in the related collection
- Min select: If set, minimum number of relations must be met
- Max select: Number of relations cannot exceed the maximum
- Required: If enabled, at least one relation must be set
Single vs multiple relations
The field behavior changes based on
maxSelect:maxSelect <= 1: Single relation mode (value is a record ID string)maxSelect > 1: Multiple relations mode (value is an array of record IDs)
Special setter modifiers
The relation field supports modifiers for manipulating relations:Go examples
- Single relation
- Multiple relations
- With min/max constraints
- With cascade delete
Database column type
The column type varies based on whether it’s single or multiple relations:Common patterns
Expand relations in API
When querying records with relations, use theexpand parameter to include related record data:
View collection restrictions
Best practices
- Use descriptive relation field names that indicate the relationship (e.g.,
author,categories,assignedTo) - Set appropriate
minSelectandmaxSelectconstraints for data integrity - Use
cascadeDeletecarefully as it can lead to unintended data loss - Consider indexing relation fields for better query performance
- Use the
expandparameter when fetching records to avoid N+1 queries - Remember that changing
collectionIdis not allowed after creation
Zero value
- Single relation: Empty string
"" - Multiple relations: Empty array
[]