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

Method wrapReference

packages/core/src/entity/Reference.ts:113–125  ·  view source on GitHub ↗

* Wraps the entity in a `Reference` wrapper if the property is defined as `ref`.

(
    entity: T | Reference<T>,
    prop: EntityProperty<O, T>,
  )

Source from the content-addressed store, hash-verified

111 * Wraps the entity in a `Reference` wrapper if the property is defined as `ref`.
112 */
113 static wrapReference<T extends object, O extends object>(
114 entity: T | Reference<T>,
115 prop: EntityProperty<O, T>,
116 ): Reference<T> | T {
117 if (entity && prop.ref && !Reference.isReference(entity)) {
118 const ref = Reference.create(entity) as Reference<T>;
119 ref.property = prop;
120
121 return ref;
122 }
123
124 return entity;
125 }
126
127 /**
128 * Returns wrapped entity.

Callers 7

setMethod · 0.80
autoWireOneToOneMethod · 0.80
assignReferenceMethod · 0.80
assignCollectionMethod · 0.80
setMethod · 0.80
propagateOneToOneMethod · 0.80

Calls 2

isReferenceMethod · 0.80
createMethod · 0.65

Tested by

no test coverage detected