@mikro-orm/core 7.0.0-dev.25 → 7.0.0-dev.27

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.
@@ -80,7 +80,7 @@ export declare class EntityRepository<Entity extends object> {
80
80
  /**
81
81
  * @inheritDoc EntityManager.findByCursor
82
82
  */
83
- findByCursor<Hint extends string = never, Fields extends string = '*', Excludes extends string = never>(where: FilterQuery<Entity>, options: FindByCursorOptions<Entity, Hint, Fields, Excludes>): Promise<Cursor<Entity, Hint, Fields, Excludes>>;
83
+ findByCursor<Hint extends string = never, Fields extends string = '*', Excludes extends string = never, IncludeCount extends boolean = true>(where: FilterQuery<Entity>, options: FindByCursorOptions<Entity, Hint, Fields, Excludes, IncludeCount>): Promise<Cursor<Entity, Hint, Fields, Excludes, IncludeCount>>;
84
84
  /**
85
85
  * Finds all entities of given type. You can pass additional options via the `options` parameter.
86
86
  */
@@ -34,10 +34,15 @@ export class Reference {
34
34
  }
35
35
  static createFromPK(entityType, pk, options) {
36
36
  const ref = this.createNakedFromPK(entityType, pk, options);
37
- return helper(ref).toReference();
37
+ return helper(ref)?.toReference() ?? ref;
38
38
  }
39
39
  static createNakedFromPK(entityType, pk, options) {
40
40
  const factory = entityType.prototype.__factory;
41
+ if (!factory) {
42
+ // this can happen only if `ref()` is used as a property initializer, and the value is important only for the
43
+ // inference of defaults, so it's fine to return it directly without wrapping with `Reference` class
44
+ return pk;
45
+ }
41
46
  const entity = factory.createReference(entityType, pk, {
42
47
  merge: false,
43
48
  convertCustomTypes: false,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mikro-orm/core",
3
3
  "type": "module",
4
- "version": "7.0.0-dev.25",
4
+ "version": "7.0.0-dev.27",
5
5
  "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.",
6
6
  "exports": {
7
7
  "./package.json": "./package.json",
@@ -54,7 +54,7 @@
54
54
  "dataloader": "2.2.3",
55
55
  "dotenv": "17.2.2",
56
56
  "esprima": "4.0.1",
57
- "mikro-orm": "7.0.0-dev.25",
57
+ "mikro-orm": "7.0.0-dev.27",
58
58
  "reflect-metadata": "0.2.2",
59
59
  "tinyglobby": "0.2.13"
60
60
  }
@@ -853,9 +853,17 @@ export class UnitOfWork {
853
853
  }
854
854
  await this.changeSetPersister.executeUpdates(changeSets, batched, { ctx });
855
855
  for (const changeSet of changeSets) {
856
- helper(changeSet.entity).__originalEntityData = this.comparator.prepareEntity(changeSet.entity);
857
- helper(changeSet.entity).__touched = false;
858
- helper(changeSet.entity).__initialized = true;
856
+ const wrapped = 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 ([ReferenceKind.MANY_TO_MANY, ReferenceKind.ONE_TO_MANY].includes(prop.kind) && changeSet.entity[prop.name] == null) {
862
+ changeSet.entity[prop.name] = Collection.create(changeSet.entity, prop.name, undefined, wrapped.isInitialized());
863
+ }
864
+ }
865
+ wrapped.__initialized = true;
866
+ }
859
867
  await this.runHooks(EventType.afterUpdate, changeSet);
860
868
  }
861
869
  }
@@ -362,7 +362,7 @@ export class EntityComparator {
362
362
  else {
363
363
  mapEntityProperties(meta);
364
364
  }
365
- lines.push(` for (let k in result) { if (Object.hasOwn(result, k) && !mapped[k]) ret[k] = result[k]; }`);
365
+ lines.push(` for (let k in result) { if (Object.hasOwn(result, k) && !mapped[k] && ret[k] === undefined) ret[k] = result[k]; }`);
366
366
  const code = `// compiled mapper for entity ${meta.className}\n`
367
367
  + `return function(result) {\n const ret = {};\n${lines.join('\n')}\n return ret;\n}`;
368
368
  const resultMapper = Utils.createFunction(context, code);