Related Collections
Configuring Many-to-Many Relationships in Umbraco UI Builder
Related collections support the editing of many-to-many relationships in UI Builder. These are used when multiple entities from one collection are linked to multiple entities from another collection, commonly represented through a junction table.
Example Use Case
A classic example is the relationship between Students and Courses, where each student takes many courses, and each course has many students.



Collections Representation
This is how the collections would be represented:

The models representing the entities would be as follows:
Defining a Related Collection
To define a related collection, follow these two steps:
Add the collection definition
Add the related collection entity picker and definition
Collection definition
Define a related collection by calling the AddRelatedCollection method on the collection config builder instance.
Using the AddRelatedCollection() Method
AddRelatedCollection() MethodThis method adds a related collection to the current collection, specifying names, descriptions, and default icons. The ID property must be defined, and the relation configuration defines the junction entity with references to parent and child entities.
Method Syntax
Example
Configuring a Related Collection Entity Picker
Define the child collection entity picker by calling the AddRelatedCollectionPickerField method on the parent collection's fieldset config.
Using the AddRelatedCollectionPickerField() Method
AddRelatedCollectionPickerField() MethodThis method adds an entity picker with the specified Data Type name to the parent collection editor.
Method Syntax
Example
Defining Repository Methods
Using the GetRelationsByParentIdImpl<>() Method
GetRelationsByParentIdImpl<>() MethodRetrieves related collections based on the ID of the parent entity.
Method Syntax
Example
Using the SaveRelationImpl<>() Method
SaveRelationImpl<>() MethodAdds a new related collection to the current parent entity.
Method Syntax
Example
Last updated
Was this helpful?