How relations work
Every relation requires two fields that reference each other:- The MANY_TO_ONE side — lives on the object that holds the foreign key.
- The ONE_TO_MANY side — lives on the object that owns the collection.
FieldType.RELATION and cross-reference each other via relationTargetFieldMetadataUniversalIdentifier.
Example: Post Card has many Recipients
APostCard can be sent to many PostCardRecipient records. Each recipient belongs to exactly one post card.
Step 1: Define the ONE_TO_MANY side on PostCard (the “one” side):
src/fields/post-card-recipients-on-post-card.field.ts
src/fields/post-card-on-post-card-recipient.field.ts
Circular imports: both relation fields reference each other’s
universalIdentifier. To avoid circular import issues, export your field IDs as named constants from each file and import them in the other. The build system resolves these at compile time.Junction relations
A junction object connects one source record to one or more target records. For example,PostCardRecipient can hold both a postCard relation and a recipient relation. On the source object’s ONE_TO_MANY field, set junctionTargetFieldUniversalIdentifier to the relation field on the junction object that points to the target:
RECIPIENT_FIELD_ID must identify a MANY_TO_ONE or morph relation on the junction object. It tells Twenty which related record is the target when a feature such as timeline activity fan-out traverses the junction.
Relating to standard objects
To create a relation with a built-in Twenty object (Person, Company, etc.), useSTANDARD_OBJECT_UNIVERSAL_IDENTIFIERS.
A relation is always declared on both objects, and this does not change when one side is a standard object: the manifest must also define the reverse field on the standard object, with the standard object’s universalIdentifier as objectUniversalIdentifier. If the reverse field is missing, the app fails to sync with Relation field target metadata not found.
src/fields/person-on-self-hosting-user.field.ts
src/fields/self-hosting-users-on-person.field.ts
Relation field properties
Inline relation fields
You can also declare a relation directly insidedefineObject. When inline, omit objectUniversalIdentifier — it’s inherited from the parent object: