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

Method hydrate

packages/core/src/entity/EntityFactory.ts:518–561  ·  view source on GitHub ↗
(
    entity: T,
    meta: EntityMetadata<T>,
    data: EntityData<T>,
    options: FactoryOptions,
  )

Source from the content-addressed store, hash-verified

516 }
517
518 private hydrate<T extends object>(
519 entity: T,
520 meta: EntityMetadata<T>,
521 data: EntityData<T>,
522 options: FactoryOptions,
523 ): void {
524 if (options.initialized) {
525 this.#hydrator.hydrate(
526 entity,
527 meta,
528 data,
529 this,
530 'full',
531 options.newEntity,
532 options.convertCustomTypes,
533 options.schema,
534 this.#driver.getSchemaName(meta, options),
535 options.normalizeAccessors,
536 );
537 } else {
538 this.#hydrator.hydrateReference(
539 entity,
540 meta,
541 data,
542 this,
543 options.convertCustomTypes,
544 options.schema,
545 this.#driver.getSchemaName(meta, options),
546 options.normalizeAccessors,
547 );
548 }
549
550 Utils.keys(data).forEach(key => {
551 helper(entity)?.__loadedProperties.add(key);
552 helper(entity)?.__serializationContext.fields?.add(key);
553 });
554
555 const processOnCreateHooksEarly =
556 options.processOnCreateHooksEarly ?? this.#config.get('processOnCreateHooksEarly');
557
558 if (options.newEntity && processOnCreateHooksEarly) {
559 this.assignDefaultValues(entity, meta);
560 }
561 }
562
563 private findEntity<T extends object>(
564 data: EntityData<T>,

Callers 2

createMethod · 0.95
mergeDataMethod · 0.95

Calls 8

assignDefaultValuesMethod · 0.95
helperFunction · 0.85
addMethod · 0.80
hydrateMethod · 0.65
getSchemaNameMethod · 0.65
hydrateReferenceMethod · 0.65
getMethod · 0.65
keysMethod · 0.45

Tested by

no test coverage detected