MCPcopy Create free account
hub / github.com/mikro-orm/mikro-orm / canPopulate

Method canPopulate

packages/core/src/EntityManager.ts:2459–2481  ·  view source on GitHub ↗

* Checks whether given property can be populated on the entity.

(entityName: EntityName<Entity>, property: string)

Source from the content-addressed store, hash-verified

2457 * Checks whether given property can be populated on the entity.
2458 */
2459 canPopulate<Entity extends object>(entityName: EntityName<Entity>, property: string): boolean {
2460 // eslint-disable-next-line prefer-const
2461 let [p, ...parts] = property.split('.');
2462 const meta = this.metadata.find(entityName);
2463
2464 if (!meta) {
2465 return true;
2466 }
2467
2468 if (p.includes(':')) {
2469 p = p.split(':', 2)[0];
2470 }
2471
2472 // For TPT inheritance, check the entity's own properties, not just the root's
2473 // For STI, meta.properties includes all properties anyway
2474 const ret = p in meta.properties;
2475
2476 if (parts.length > 0) {
2477 return this.canPopulate(meta.properties[p as EntityKey<Entity>].targetMeta!.class, parts.join('.'));
2478 }
2479
2480 return ret;
2481 }
2482
2483 /**
2484 * Loads specified relations in batch. This will execute one query for each relation, that will populate it on all the specified entities.

Callers 2

preparePopulateMethod · 0.95

Calls 2

findMethod · 0.65
joinMethod · 0.65

Tested by

no test coverage detected