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

Method processEntity

packages/core/src/utils/Cursor.ts:114–155  ·  view source on GitHub ↗
(
      entity: T,
      prop: EntityKey<T>,
      direction: QueryOrderKeys<T>,
      object = false,
    )

Source from the content-addressed store, hash-verified

112 */
113 from(entity: Entity | Loaded<Entity, Hint, Fields, Excludes>): string {
114 const processEntity = <T extends object>(
115 entity: T,
116 prop: EntityKey<T>,
117 direction: QueryOrderKeys<T>,
118 object = false,
119 ) => {
120 if (Utils.isPlainObject(direction)) {
121 const unwrapped = Reference.unwrapReference(entity[prop] as T);
122
123 // Check if the relation is loaded - for nested properties, undefined means not populated
124 if (Utils.isEntity(unwrapped) && !helper(unwrapped).isInitialized()) {
125 throw CursorError.entityNotPopulated(entity, prop);
126 }
127
128 return Utils.keys(direction).reduce((o, key) => {
129 Object.assign(o, processEntity(unwrapped, key, direction[key] as QueryOrderKeys<T>, true));
130 return o;
131 }, {} as Dictionary);
132 }
133
134 let value: unknown = entity[prop];
135
136 // Allow null/undefined values in cursor - they will be handled in createCursorCondition
137 // undefined can occur with forceUndefined config option which converts null to undefined
138 if (value == null) {
139 return object ? { [prop]: null } : null;
140 }
141
142 if (Utils.isEntity(value, true)) {
143 value = helper(value).getPrimaryKey();
144 }
145
146 if (Utils.isScalarReference(value)) {
147 value = value.unwrap();
148 }
149
150 if (object) {
151 return { [prop]: value };
152 }
153
154 return value;
155 };
156 const value = this.#definition.map(([key, direction]) => processEntity(entity as Entity, key, direction));
157 return Cursor.encode(value);
158 }

Callers

nothing calls this directly

Calls 12

helperFunction · 0.85
isPlainObjectMethod · 0.80
unwrapReferenceMethod · 0.80
entityNotPopulatedMethod · 0.80
reduceMethod · 0.80
isInitializedMethod · 0.65
assignMethod · 0.65
getPrimaryKeyMethod · 0.65
isEntityMethod · 0.45
keysMethod · 0.45
isScalarReferenceMethod · 0.45
unwrapMethod · 0.45

Tested by

no test coverage detected