@mikro-orm/core 7.2.7-dev.12 → 7.2.7-dev.14

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.
@@ -817,11 +817,14 @@ export class MetadataDiscovery {
817
817
  else {
818
818
  pivotMeta2.compositePK = true;
819
819
  }
820
+ // STI entities share one table, so any m:n within the hierarchy is self-referencing, named after the root
821
+ const stiRoot = meta.root.inheritanceType === 'sti' ? meta.root : undefined;
822
+ const baseMeta = stiRoot ?? meta;
820
823
  // handle self-referenced m:n with same default field names
821
- if (meta.className === targetType &&
824
+ if ((meta.className === targetType || stiRoot === targetMeta.root) &&
822
825
  prop.joinColumns.every((joinColumn, idx) => joinColumn === prop.inverseJoinColumns[idx])) {
823
826
  // use tableName only when explicitly provided by user, otherwise use className for backwards compatibility
824
- const baseName = this.isExplicitTableName(meta) ? meta.tableName : meta.className;
827
+ const baseName = this.isExplicitTableName(baseMeta) ? baseMeta.tableName : baseMeta.className;
825
828
  prop.joinColumns = prop.referencedColumnNames.map(name => this.#namingStrategy.joinKeyColumnName(baseName + '_1', name, meta.compositePK));
826
829
  prop.inverseJoinColumns = prop.referencedColumnNames.map(name => this.#namingStrategy.joinKeyColumnName(baseName + '_2', name, meta.compositePK));
827
830
  if (prop.inversedBy) {
@@ -829,13 +832,18 @@ export class MetadataDiscovery {
829
832
  prop2.inverseJoinColumns = prop.joinColumns;
830
833
  prop2.joinColumns = prop.inverseJoinColumns;
831
834
  }
832
- // propagate updated joinColumns to all child entities that inherit this property (STI)
833
- for (const childMeta of this.#discovered.filter(m => m.root === meta && m !== meta)) {
835
+ // propagate updated joinColumns to all entities of the hierarchy that inherit this property or its inverse (STI)
836
+ for (const childMeta of this.#discovered.filter(m => m.root === baseMeta)) {
834
837
  const childProp = childMeta.properties[prop.name];
835
838
  if (childProp) {
836
839
  childProp.joinColumns = prop.joinColumns;
837
840
  childProp.inverseJoinColumns = prop.inverseJoinColumns;
838
841
  }
842
+ const childProp2 = prop.inversedBy ? childMeta.properties[prop.inversedBy] : undefined;
843
+ if (childProp2) {
844
+ childProp2.inverseJoinColumns = prop.joinColumns;
845
+ childProp2.joinColumns = prop.inverseJoinColumns;
846
+ }
839
847
  }
840
848
  }
841
849
  // Union-target polymorphic M:N: discriminator + target FK share the pivot across multiple target types
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/core",
3
- "version": "7.2.7-dev.12",
3
+ "version": "7.2.7-dev.14",
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
@@ -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.7-dev.12';
156
+ static #ORM_VERSION = '7.2.7-dev.14';
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}`;