* Checks whether given property can be populated on the entity.
(entityName: EntityName<Entity>, property: string)
| 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. |
no test coverage detected