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

Method map

packages/core/src/EntityManager.ts:2021–2049  ·  view source on GitHub ↗

* Maps raw database result to an entity and merges it to this EntityManager.

(
    entityName: EntityName<Entity>,
    result: EntityDictionary<Entity>,
    options: { schema?: string; mapped?: boolean } = {},
  )

Source from the content-addressed store, hash-verified

2019 * Maps raw database result to an entity and merges it to this EntityManager.
2020 */
2021 map<Entity extends object>(
2022 entityName: EntityName<Entity>,
2023 result: EntityDictionary<Entity>,
2024 options: { schema?: string; mapped?: boolean } = {},
2025 ): Entity {
2026 const { mapped, ...rest } = options;
2027 const meta = this.metadata.get(entityName);
2028 const data = (mapped ? result : this.driver.mapResult(result, meta)) as Dictionary;
2029
2030 for (const k of Object.keys(data)) {
2031 const prop = meta.properties[k as EntityKey<Entity>];
2032
2033 if (
2034 prop?.kind === ReferenceKind.SCALAR &&
2035 SCALAR_TYPES.has(prop.runtimeType) &&
2036 !prop.customType &&
2037 (prop.setter || !prop.getter)
2038 ) {
2039 validateProperty(prop, data[k], data);
2040 }
2041 }
2042
2043 return this.merge<Entity>(entityName, data as EntityData<Entity>, {
2044 convertCustomTypes: true,
2045 refresh: true,
2046 validate: false,
2047 ...rest,
2048 });
2049 }
2050
2051 /**
2052 * Merges given entity to this EntityManager so it becomes managed. You can force refreshing of existing entities

Callers 15

callRoutineMethod · 0.45
fetchRefcursorsMethod · 0.45
createMethod · 0.45
dropMethod · 0.45
ensureIndexesMethod · 0.45
mapIndexPropertiesMethod · 0.45
executeQueryMethod · 0.45
streamMethod · 0.45
findMethod · 0.45
findOneMethod · 0.45
nativeInsertManyMethod · 0.45

Calls 6

mergeMethod · 0.95
validatePropertyFunction · 0.85
getMethod · 0.65
mapResultMethod · 0.65
hasMethod · 0.65
keysMethod · 0.45

Tested by 15

getReferencesFunction · 0.36
getCollectionsFunction · 0.36
getRefsFunction · 0.36
getColsFunction · 0.36
constructorMethod · 0.36
constructorMethod · 0.36
constructorMethod · 0.36
constructorMethod · 0.36
constructorMethod · 0.36
constructorMethod · 0.36
loadORMFunction · 0.36
createStatementMethod · 0.36