@mikro-orm/core 6.5.4-dev.3 → 6.5.4-dev.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -39,10 +39,15 @@ class Reference {
39
39
  }
40
40
  static createFromPK(entityType, pk, options) {
41
41
  const ref = this.createNakedFromPK(entityType, pk, options);
42
- return (0, wrap_1.helper)(ref).toReference();
42
+ return (0, wrap_1.helper)(ref)?.toReference() ?? ref;
43
43
  }
44
44
  static createNakedFromPK(entityType, pk, options) {
45
45
  const factory = entityType.prototype.__factory;
46
+ if (!factory) {
47
+ // this can happen only if `ref()` is used as a property initializer, and the value is important only for the
48
+ // inference of defaults, so it's fine to return it directly without wrapping with `Reference` class
49
+ return pk;
50
+ }
46
51
  const entity = factory.createReference(entityType, pk, {
47
52
  merge: false,
48
53
  convertCustomTypes: false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/core",
3
- "version": "6.5.4-dev.3",
3
+ "version": "6.5.4-dev.5",
4
4
  "description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.",
5
5
  "main": "index.js",
6
6
  "module": "index.mjs",
@@ -64,7 +64,7 @@
64
64
  "esprima": "4.0.1",
65
65
  "fs-extra": "11.3.2",
66
66
  "globby": "11.1.0",
67
- "mikro-orm": "6.5.4-dev.3",
67
+ "mikro-orm": "6.5.4-dev.5",
68
68
  "reflect-metadata": "0.2.2"
69
69
  }
70
70
  }
@@ -853,9 +853,17 @@ class UnitOfWork {
853
853
  }
854
854
  await this.changeSetPersister.executeUpdates(changeSets, batched, { ctx });
855
855
  for (const changeSet of changeSets) {
856
- (0, entity_1.helper)(changeSet.entity).__originalEntityData = this.comparator.prepareEntity(changeSet.entity);
857
- (0, entity_1.helper)(changeSet.entity).__touched = false;
858
- (0, entity_1.helper)(changeSet.entity).__initialized = true;
856
+ const wrapped = (0, entity_1.helper)(changeSet.entity);
857
+ wrapped.__originalEntityData = this.comparator.prepareEntity(changeSet.entity);
858
+ wrapped.__touched = false;
859
+ if (!wrapped.__initialized) {
860
+ for (const prop of changeSet.meta.relations) {
861
+ if ([enums_1.ReferenceKind.MANY_TO_MANY, enums_1.ReferenceKind.ONE_TO_MANY].includes(prop.kind) && changeSet.entity[prop.name] == null) {
862
+ changeSet.entity[prop.name] = entity_1.Collection.create(changeSet.entity, prop.name, undefined, wrapped.isInitialized());
863
+ }
864
+ }
865
+ wrapped.__initialized = true;
866
+ }
859
867
  await this.runHooks(enums_1.EventType.afterUpdate, changeSet);
860
868
  }
861
869
  }