@mikro-orm/core 7.2.5-dev.7 → 7.2.5-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.
@@ -1626,7 +1626,7 @@ export class MetadataDiscovery {
1626
1626
  if (meta.inheritanceType !== 'tpt') {
1627
1627
  return;
1628
1628
  }
1629
- const belongsToTable = (prop) => prop.persist !== false || prop.primary;
1629
+ const belongsToTable = (prop) => prop.persist !== false || prop.primary || !!prop.formula;
1630
1630
  // Use meta.properties (object) since meta.props (array) may not be populated yet
1631
1631
  const allProps = Object.values(meta.properties);
1632
1632
  if (!meta.tptParent) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/core",
3
- "version": "7.2.5-dev.7",
3
+ "version": "7.2.5-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
  "keywords": [
6
6
  "data-mapper",
@@ -44,7 +44,8 @@ export class CommitOrderCalculator {
44
44
  if (!toOneOwner && !toManyOwner) {
45
45
  return;
46
46
  }
47
- const propertyType = prop.targetMeta?.root._id;
47
+ // TPT tables are separate nodes and the FK references the target's own table, not the root
48
+ const propertyType = (prop.targetMeta?.inheritanceType === 'tpt' ? prop.targetMeta : prop.targetMeta?.root)?._id;
48
49
  if (propertyType == null || !this.hasNode(propertyType)) {
49
50
  return;
50
51
  }
@@ -1283,6 +1283,13 @@ export class UnitOfWork {
1283
1283
  calc.discoverProperty({ ...prop, targetMeta }, meta._id);
1284
1284
  }
1285
1285
  }
1286
+ else if (prop.targetMeta?.inheritanceType === 'tpt') {
1287
+ calc.discoverProperty(prop, meta._id);
1288
+ // a TPT subclass delete has only a leaf change set that also removes the target row; weak edge so it can't break insert order
1289
+ for (const targetMeta of this.#metadata.find(prop.targetMeta.class).allTPTDescendants ?? []) {
1290
+ calc.discoverProperty({ ...prop, targetMeta, nullable: true }, meta._id);
1291
+ }
1292
+ }
1286
1293
  else {
1287
1294
  calc.discoverProperty(prop, meta._id);
1288
1295
  }
@@ -366,8 +366,16 @@ export class EntityComparator {
366
366
  if (prop.renamedFrom) {
367
367
  lines.push(`${padding} ${this.propName(prop.fieldNames[0], 'mapped')} = true;`);
368
368
  defined = `${this.propName(prop.fieldNames[0])} != null`;
369
- // a column shared with a differently typed subtype is left for each subtype's hydrator to convert
370
- if (meta.props.some(p => p !== prop && p.name === prop.name && p.fieldNames?.[0] === prop.fieldNames[0])) {
369
+ const sharesColumn = meta.props.some(p => p !== prop && p.name === prop.name && p.fieldNames?.[0] === prop.fieldNames[0]);
370
+ // hydrators expect mapped embeddable keys, so a shared object embeddable is mapped only for its own subtypes
371
+ if (sharesColumn && prop.kind === ReferenceKind.EMBEDDED && prop.object && meta.discriminatorMap) {
372
+ const owners = Object.entries(meta.discriminatorMap)
373
+ .filter(([, cls]) => this.#metadata.find(cls)?.properties[prop.name]?.targetMeta === prop.targetMeta)
374
+ .map(([value]) => `${this.propName(meta.discriminatorColumn)} == ${JSON.stringify(value)}`);
375
+ defined += ` && (${owners.join(' || ')})`;
376
+ }
377
+ else if (sharesColumn) {
378
+ // a column shared with a differently typed subtype is left for each subtype's hydrator to convert
371
379
  lines.push(`${padding} if (${defined}) {`);
372
380
  lines.push(`${padding} ret${this.wrap(prop.name)} = ${this.propName(prop.fieldNames[0])};`);
373
381
  lines.push(`${padding} }`);
package/utils/Utils.js CHANGED
@@ -153,7 +153,7 @@ export function parseJsonSafe(value) {
153
153
  /** Collection of general-purpose utility methods used throughout the ORM. */
154
154
  export class Utils {
155
155
  static PK_SEPARATOR = '~~~';
156
- static #ORM_VERSION = '7.2.5-dev.7';
156
+ static #ORM_VERSION = '7.2.5-dev.9';
157
157
  /** Default session variable name backing an RLS filter argument (`current_setting('mikro.<filter>.<arg>')`). */
158
158
  static getRlsSettingName(filterName, argName) {
159
159
  return `mikro.${filterName}.${argName}`;