* preload everything in one call (this will update already existing references in IM)
(
entityName: EntityName<Entity>,
entities: Entity[],
populate: PopulateOptions<Entity>,
options: Required<EntityLoaderOptions<Entity>>,
)
| 279 | * preload everything in one call (this will update already existing references in IM) |
| 280 | */ |
| 281 | private async populateMany<Entity extends object>( |
| 282 | entityName: EntityName<Entity>, |
| 283 | entities: Entity[], |
| 284 | populate: PopulateOptions<Entity>, |
| 285 | options: Required<EntityLoaderOptions<Entity>>, |
| 286 | ): Promise<AnyEntity[]> { |
| 287 | const [field, ref] = populate.field.split(':', 2) as [EntityKey<Entity>, string | undefined]; |
| 288 | const meta = this.#metadata.find<Entity>(entityName)!; |
| 289 | const prop = meta.properties[field]; |
| 290 | |
| 291 | if (prop.kind === ReferenceKind.MANY_TO_MANY && prop.owner && !this.#driver.getPlatform().usesPivotTable()) { |
| 292 | const filtered = entities.filter(e => !(e[prop.name] as Collection<any>)?.isInitialized()); |
| 293 | |
| 294 | if (filtered.length > 0) { |
| 295 | await this.populateScalar(meta, filtered, { ...options, fields: [prop.name] as any }); |
| 296 | } |
| 297 | } |
| 298 | |
| 299 | if (prop.kind === ReferenceKind.SCALAR && prop.lazy) { |
| 300 | const filtered = entities.filter( |
| 301 | e => |
| 302 | options.refresh || |
| 303 | (prop.ref ? !(e[prop.name] as ScalarReference<any>)?.isInitialized() : e[prop.name] === undefined), |
| 304 | ); |
| 305 | |
| 306 | if (options.ignoreLazyScalarProperties || filtered.length === 0) { |
| 307 | return entities as AnyEntity[]; |
| 308 | } |
| 309 | |
| 310 | await this.populateScalar(meta, filtered, { ...options, fields: [prop.name] as any }); |
| 311 | |
| 312 | return entities as AnyEntity[]; |
| 313 | } |
| 314 | |
| 315 | if (prop.kind === ReferenceKind.EMBEDDED) { |
| 316 | return []; |
| 317 | } |
| 318 | |
| 319 | const filtered = this.filterCollections<Entity>(entities, field, options, ref); |
| 320 | const innerOrderBy = Utils.asArray(options.orderBy) |
| 321 | .filter( |
| 322 | orderBy => |
| 323 | (Array.isArray(orderBy[prop.name]) && (orderBy[prop.name] as unknown[]).length > 0) || |
| 324 | Utils.isObject(orderBy[prop.name]), |
| 325 | ) |
| 326 | .flatMap(orderBy => orderBy[prop.name]); |
| 327 | const where = await this.extractChildCondition(options, prop); |
| 328 | const mergedOrderBy = populate.orderBy ? Utils.asArray(populate.orderBy) : innerOrderBy; |
| 329 | |
| 330 | if (prop.kind === ReferenceKind.MANY_TO_MANY && this.#driver.getPlatform().usesPivotTable()) { |
| 331 | const pivotOrderBy = QueryHelper.mergeOrderBy<Entity>(mergedOrderBy, prop.orderBy, prop.targetMeta?.orderBy); |
| 332 | const res = await this.findChildrenFromPivotTable<Entity>(filtered, prop, options, pivotOrderBy, populate, !!ref); |
| 333 | return Utils.flatten(res); |
| 334 | } |
| 335 | |
| 336 | if (prop.polymorphic && prop.polymorphTargets) { |
| 337 | return this.populatePolymorphic<Entity>(entities, prop, options, !!ref); |
| 338 | } |
nothing calls this directly
no test coverage detected