@mikro-orm/core 7.1.6-dev.12 → 7.1.6-dev.13

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.
@@ -122,7 +122,11 @@ export class EntityFactory {
122
122
  newEntity: options.newEntity,
123
123
  loaded: options.initialized,
124
124
  });
125
- if (options.recomputeSnapshot) {
125
+ // A reference seeded from a raw scalar PK with `convertCustomTypes: false` (e.g. `em.getReference()` or a to-one
126
+ // relation assigned a raw scalar in `em.create()`) keeps its snapshot in JS-form, while `prepareEntity()` derives
127
+ // DB-form — so for a custom type mapping between different shapes (e.g. ULID <-> UUID) they always diff, yielding a
128
+ // spurious PK update on every flush. Recompute the snapshot from the entity to keep it in DB-form (GH #7966).
129
+ if (options.recomputeSnapshot || (!options.convertCustomTypes && !options.initialized)) {
126
130
  wrapped.__originalEntityData = this.#comparator.prepareEntity(entity);
127
131
  }
128
132
  }
@@ -189,8 +193,7 @@ export class EntityFactory {
189
193
  [ReferenceKind.MANY_TO_ONE, ReferenceKind.ONE_TO_ONE, ReferenceKind.SCALAR].includes(prop.kind) &&
190
194
  prop.customType?.ensureComparable(meta, prop) &&
191
195
  diff2[key] != null) {
192
- const converted = prop.customType.convertToJSValue(diff2[key], this.#platform, { force: true });
193
- diff2[key] = prop.customType.convertToDatabaseValue(converted, this.#platform, { fromQuery: true });
196
+ diff2[key] = prop.customType.convertToDatabaseValue(diff2[key], this.#platform, { fromQuery: true });
194
197
  }
195
198
  originalEntityData[key] = diff2[key] === null ? nullVal : diff2[key];
196
199
  helper(entity).__loadedProperties.add(key);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/core",
3
- "version": "7.1.6-dev.12",
3
+ "version": "7.1.6-dev.13",
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
  "keywords": [
6
6
  "data-mapper",
package/utils/Utils.js CHANGED
@@ -141,7 +141,7 @@ export function parseJsonSafe(value) {
141
141
  /** Collection of general-purpose utility methods used throughout the ORM. */
142
142
  export class Utils {
143
143
  static PK_SEPARATOR = '~~~';
144
- static #ORM_VERSION = '7.1.6-dev.12';
144
+ static #ORM_VERSION = '7.1.6-dev.13';
145
145
  /**
146
146
  * Checks if the argument is instance of `Object`. Returns false for arrays.
147
147
  */