@@ -55,6 +55,52 @@ export default class EntityAssociationLoader<
5555 return await loader . loadByIDAsync ( ( associatedEntityID as unknown ) as TAssociatedID ) ;
5656 }
5757
58+ /**
59+ * Load many entities associated with this entity, often referred to as entites belonging
60+ * to this entity. In a relational database, the field in the foreign entity is a
61+ * foreign key to the ID of this entity. Also commonly referred to as a has many relationship,
62+ * where this entity has many associated entities.
63+ * @param associatedEntityClass - class of the associated entities
64+ * @param associatedEntityFieldContainingThisID - field of associated entity which contains the ID of this entity
65+ * @param queryContext - query context in which to perform the load
66+ */
67+ async loadManyAssociatedEntitiesAsync <
68+ TAssociatedFields ,
69+ TAssociatedID ,
70+ TAssociatedEntity extends ReadonlyEntity < TAssociatedFields , TAssociatedID , TViewerContext > ,
71+ TAssociatedPrivacyPolicy extends EntityPrivacyPolicy <
72+ TAssociatedFields ,
73+ TAssociatedID ,
74+ TViewerContext ,
75+ TAssociatedEntity
76+ >
77+ > (
78+ associatedEntityClass : IEntityClass <
79+ TAssociatedFields ,
80+ TAssociatedID ,
81+ TViewerContext ,
82+ TAssociatedEntity ,
83+ TAssociatedPrivacyPolicy
84+ > ,
85+ associatedEntityFieldContainingThisID : keyof TAssociatedFields ,
86+ queryContext : EntityQueryContext = this . entity
87+ . getViewerContext ( )
88+ . getViewerScopedEntityCompanionForClass ( associatedEntityClass )
89+ . getQueryContextProvider ( )
90+ . getRegularEntityQueryContext ( )
91+ ) : Promise < readonly Result < TAssociatedEntity > [ ] > {
92+ const thisID = this . entity . getID ( ) ;
93+ const loader = this . entity
94+ . getViewerContext ( )
95+ . getViewerScopedEntityCompanionForClass ( associatedEntityClass )
96+ . getLoaderFactory ( )
97+ . forLoad ( queryContext ) ;
98+ return await loader . loadManyByFieldEqualingAsync (
99+ associatedEntityFieldContainingThisID ,
100+ thisID as any
101+ ) ;
102+ }
103+
58104 /**
59105 * Load an associated entity identified by a field value of this entity. In a relational database,
60106 * the field in this entity is a foreign key to a unique field of the associated entity.
@@ -101,6 +147,52 @@ export default class EntityAssociationLoader<
101147 ) ;
102148 }
103149
150+ /**
151+ * Load many associated entities identified by a field value of this entity. In a relational database,
152+ * the field in this entity refers to a field of the associated entity.
153+ * @param fieldIdentifyingAssociatedEntity - field of this entity containing the value with which to look up associated entities
154+ * @param associatedEntityClass - class of the associated entities
155+ * @param associatedEntityLookupByField - field of associated entities with which to look up the associated entities
156+ * @param queryContext - query context in which to perform the load
157+ */
158+ async loadManyAssociatedEntitiesByFieldEqualingAsync <
159+ TAssociatedFields ,
160+ TAssociatedID ,
161+ TAssociatedEntity extends ReadonlyEntity < TAssociatedFields , TAssociatedID , TViewerContext > ,
162+ TAssociatedPrivacyPolicy extends EntityPrivacyPolicy <
163+ TAssociatedFields ,
164+ TAssociatedID ,
165+ TViewerContext ,
166+ TAssociatedEntity
167+ >
168+ > (
169+ fieldIdentifyingAssociatedEntity : keyof TFields ,
170+ associatedEntityClass : IEntityClass <
171+ TAssociatedFields ,
172+ TAssociatedID ,
173+ TViewerContext ,
174+ TAssociatedEntity ,
175+ TAssociatedPrivacyPolicy
176+ > ,
177+ associatedEntityLookupByField : keyof TAssociatedFields ,
178+ queryContext : EntityQueryContext = this . entity
179+ . getViewerContext ( )
180+ . getViewerScopedEntityCompanionForClass ( associatedEntityClass )
181+ . getQueryContextProvider ( )
182+ . getRegularEntityQueryContext ( )
183+ ) : Promise < readonly Result < TAssociatedEntity > [ ] > {
184+ const associatedFieldValue = this . entity . getField ( fieldIdentifyingAssociatedEntity ) ;
185+ const loader = this . entity
186+ . getViewerContext ( )
187+ . getViewerScopedEntityCompanionForClass ( associatedEntityClass )
188+ . getLoaderFactory ( )
189+ . forLoad ( queryContext ) ;
190+ return await loader . loadManyByFieldEqualingAsync (
191+ associatedEntityLookupByField ,
192+ associatedFieldValue as any
193+ ) ;
194+ }
195+
104196 /**
105197 * Load an associated entity by folding a sequence of {@link EntityLoadThroughDirective}. At each
106198 * fold step, load an associated entity identified by a field value of the current fold value.
0 commit comments