Retrieve Child Collections
Configuring one-to-many relationships in Umbraco UI Builder.
This page is a work in progress and may undergo further revisions, updates, or amendments. The information contained herein is subject to change without notice.
In one-to-many relationships, a parent entity is associated with multiple entities from another collection. In Umbraco UI Builder, retrieving child collections from such relationships is supported through child repositories. This enables you to access related data effectively, helping to maintain a well-organized backoffice UI.
Models Representation
For a one-to-many relationship, you typically have two models: one for the parent entity and one for the child entity.
In the above example, the Student
model represents the parent entity. A student can have multiple associated StudentProjects
.
The StudentProjects
model represents the child entity. The StudentId
is a foreign key that links each StudentProject
to the Student
entity, establishing the one-to-many relationship.
Child Repositories
To retrieve data from child collections, you can use the IRepositoryFactory
to create child repository instances. These repositories provide methods to fetch child entities associated with a given parent entity.
In this example:
The
StudentProjectController
is using theIRepositoryFactory
to create a child repository forStudentProject
.The
GetAll()
method retrieves all child entities related to the given parent.The
GetCount()
method returns the total number of child entities associated with the parent.The
GetPaged()
method allows for pagination of child entities, making it easier to manage large sets of data.
This structure allows efficient retrieval and management of child entities, providing a well-organized way to interact with related data in Umbraco's backoffice.
Last updated
Was this helpful?