@mikro-orm/core 6.4.17-dev.7 → 6.4.17-dev.9

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/core",
3
- "version": "6.4.17-dev.7",
3
+ "version": "6.4.17-dev.9",
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.0",
66
66
  "globby": "11.1.0",
67
- "mikro-orm": "6.4.17-dev.7",
67
+ "mikro-orm": "6.4.17-dev.9",
68
68
  "reflect-metadata": "0.2.2"
69
69
  }
70
70
  }
@@ -144,7 +144,9 @@ class ChangeSetComputer {
144
144
  if (!target.isDirty() && changeSet.type !== ChangeSet_1.ChangeSetType.CREATE) {
145
145
  return;
146
146
  }
147
- this.collectionUpdates.add(target);
147
+ if (target.isDirty()) {
148
+ this.collectionUpdates.add(target);
149
+ }
148
150
  if (prop.owner && !this.platform.usesPivotTable()) {
149
151
  changeSet.payload[prop.name] = target.getItems(false).map((item) => item.__helper.__identifier ?? item.__helper.getPrimaryKey());
150
152
  }
@@ -102,6 +102,7 @@ export declare class UnitOfWork {
102
102
  private commitDeleteChangeSets;
103
103
  private commitExtraUpdates;
104
104
  private commitCollectionUpdates;
105
+ private filterCollectionUpdates;
105
106
  /**
106
107
  * Orders change sets so FK constrains are maintained, ensures stable order (needed for node < 11)
107
108
  */
@@ -303,6 +303,7 @@ class UnitOfWork {
303
303
  cs.entity.__helper.__processing = true;
304
304
  }
305
305
  await this.eventManager.dispatchEvent(enums_1.EventType.onFlush, { em: this.em, uow: this });
306
+ this.filterCollectionUpdates();
306
307
  // nothing to do, do not start transaction
307
308
  if (this.changeSets.size === 0 && this.collectionUpdates.size === 0 && this.extraUpdates.size === 0) {
308
309
  return void await this.eventManager.dispatchEvent(enums_1.EventType.afterFlush, { em: this.em, uow: this });
@@ -886,23 +887,29 @@ class UnitOfWork {
886
887
  }
887
888
  }
888
889
  async commitCollectionUpdates(ctx) {
889
- const collectionUpdates = [];
890
+ this.filterCollectionUpdates();
891
+ await this.em.getDriver().syncCollections(this.collectionUpdates, { ctx, schema: this.em.schema });
890
892
  for (const coll of this.collectionUpdates) {
893
+ coll.takeSnapshot();
894
+ }
895
+ }
896
+ filterCollectionUpdates() {
897
+ for (const coll of this.collectionUpdates) {
898
+ let skip = true;
891
899
  if (coll.property.owner || coll.getItems(false).filter(item => !item.__helper.__initialized).length > 0) {
892
900
  if (this.platform.usesPivotTable()) {
893
- collectionUpdates.push(coll);
901
+ skip = false;
894
902
  }
895
903
  }
896
904
  else if (coll.property.kind === enums_1.ReferenceKind.ONE_TO_MANY && coll.getSnapshot() === undefined) {
897
- collectionUpdates.push(coll);
905
+ skip = false;
898
906
  }
899
907
  else if (coll.property.kind === enums_1.ReferenceKind.MANY_TO_MANY && !coll.property.owner) {
900
- collectionUpdates.push(coll);
908
+ skip = false;
909
+ }
910
+ if (skip) {
911
+ this.collectionUpdates.delete(coll);
901
912
  }
902
- }
903
- await this.em.getDriver().syncCollections(collectionUpdates, { ctx, schema: this.em.schema });
904
- for (const coll of this.collectionUpdates) {
905
- coll.takeSnapshot();
906
913
  }
907
914
  }
908
915
  /**