@mikro-orm/core 6.6.12-dev.0 → 6.6.12-dev.2

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.
@@ -222,7 +222,8 @@ class EntityHelper {
222
222
  // Inverse already points to owner — propagation is not needed,
223
223
  // but we still need to clean up old's inverse side.
224
224
  (0, wrap_1.helper)(old).__pk ??= (0, wrap_1.helper)(old).getPrimaryKey();
225
- if (old[prop2.name] != null) {
225
+ // Don't nullify the FK if it's part of the PK — the entity will be deleted via orphan removal
226
+ if (old[prop2.name] != null && !(prop.orphanRemoval && prop2.primary)) {
226
227
  delete (0, wrap_1.helper)(old).__data[prop2.name];
227
228
  old[prop2.name] = null;
228
229
  }
@@ -258,7 +259,8 @@ class EntityHelper {
258
259
  else {
259
260
  entity[prop2.name] = Reference_1.Reference.wrapReference(owner, prop);
260
261
  }
261
- if (old?.[prop2.name] != null) {
262
+ // Don't nullify the FK if it's part of the PK — the entity will be deleted via orphan removal
263
+ if (old?.[prop2.name] != null && !(prop.orphanRemoval && prop2.primary)) {
262
264
  delete (0, wrap_1.helper)(old).__data[prop2.name];
263
265
  old[prop2.name] = null;
264
266
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/core",
3
- "version": "6.6.12-dev.0",
3
+ "version": "6.6.12-dev.2",
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.3",
66
66
  "globby": "11.1.0",
67
- "mikro-orm": "6.6.12-dev.0",
67
+ "mikro-orm": "6.6.12-dev.2",
68
68
  "reflect-metadata": "0.2.2"
69
69
  }
70
70
  }
@@ -73,6 +73,7 @@ export declare class EntityComparator {
73
73
  */
74
74
  private shouldSerialize;
75
75
  private getEmbeddedPropertySnapshot;
76
+ private getInlineEmbeddedNullLines;
76
77
  private registerCustomType;
77
78
  private getPropertySnapshot;
78
79
  /**
@@ -436,12 +436,7 @@ class EntityComparator {
436
436
  }
437
437
  else {
438
438
  ret += `${padding}if (${nullCond}) {\n`;
439
- ret += meta.props.filter(p => p.embedded?.[0] === prop.name
440
- // object for JSON embeddable
441
- && (p.object || (p.persist !== false))).map(childProp => {
442
- const childDataKey = meta.embeddable || prop.object ? dataKey + this.wrap(childProp.embedded[1]) : this.wrap(childProp.name);
443
- return `${padding} ret${childDataKey} = null;`;
444
- }).join('\n') + `\n`;
439
+ ret += this.getInlineEmbeddedNullLines(meta, prop.name, padding, dataKey, !!(meta.embeddable || prop.object)).join('\n') + `\n`;
445
440
  ret += `${padding}}\n`;
446
441
  }
447
442
  const cond = `entity${path.map(k => this.wrap(k)).join('')} != null`;
@@ -485,6 +480,16 @@ class EntityComparator {
485
480
  }
486
481
  return `${ret}${padding}}`;
487
482
  }
483
+ getInlineEmbeddedNullLines(meta, parentName, padding, dataKey, useEmbeddedKey) {
484
+ return meta.props.filter(p => p.embedded?.[0] === parentName
485
+ && (p.object || (p.persist !== false))).flatMap(childProp => {
486
+ const childDataKey = useEmbeddedKey ? dataKey + this.wrap(childProp.embedded[1]) : this.wrap(childProp.name);
487
+ if (childProp.kind === enums_1.ReferenceKind.EMBEDDED && !childProp.object) {
488
+ return this.getInlineEmbeddedNullLines(meta, childProp.name, padding, childDataKey, useEmbeddedKey);
489
+ }
490
+ return [`${padding} ret${childDataKey} = null;`];
491
+ });
492
+ }
488
493
  registerCustomType(prop, context) {
489
494
  const convertorKey = this.safeKey(prop.name);
490
495
  context.set(`convertToDatabaseValue_${convertorKey}`, (val) => {