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

Method getReference

packages/core/src/EntityManager.ts:2266–2290  ·  view source on GitHub ↗

* 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 = {},
  )

Source from the content-addressed store, hash-verified

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.

Calls 6

getEntityFactoryMethod · 0.95
isPrimaryKeyMethod · 0.80
createReferenceMethod · 0.80
getMethod · 0.65
createMethod · 0.65

Tested by 2

getReferencesFunction · 0.36
saveBookFunction · 0.36