* Gets a reference to the entity identified by the given type and identifier without actually loading it, if the entity is not yet loaded
(
entityName: EntityName<Entity>,
id: Primary<Entity>,
options: GetReferenceOptions = {},
)
| 2264 | * Gets a reference to the entity identified by the given type and identifier without actually loading it, if the entity is not yet loaded |
| 2265 | */ |
| 2266 | getReference<Entity extends object>( |
| 2267 | entityName: EntityName<Entity>, |
| 2268 | id: Primary<Entity>, |
| 2269 | options: GetReferenceOptions = {}, |
| 2270 | ): Entity | Ref<Entity> | Reference<Entity> { |
| 2271 | options.schema ??= this.schema; |
| 2272 | options.convertCustomTypes ??= false; |
| 2273 | const meta = this.metadata.get(entityName); |
| 2274 | |
| 2275 | if (Utils.isPrimaryKey(id)) { |
| 2276 | if (meta.compositePK) { |
| 2277 | throw ValidationError.invalidCompositeIdentifier(meta); |
| 2278 | } |
| 2279 | |
| 2280 | id = [id] as Primary<Entity>; |
| 2281 | } |
| 2282 | |
| 2283 | const entity = this.getEntityFactory().createReference<Entity>(entityName, id, { merge: true, ...options }); |
| 2284 | |
| 2285 | if (options.wrapped) { |
| 2286 | return Reference.create(entity); |
| 2287 | } |
| 2288 | |
| 2289 | return entity; |
| 2290 | } |
| 2291 | |
| 2292 | /** |
| 2293 | * Returns total number of entities matching your `where` query. |