@mikro-orm/core 7.2.2-dev.22 → 7.2.2-dev.24

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.
@@ -547,7 +547,7 @@ export class MetadataDiscovery {
547
547
  const fieldNames1 = prop.targetMeta.getPrimaryProps().flatMap(pk => pk.fieldNames);
548
548
  const idColumns = fieldNames1.map(fieldName => this.#namingStrategy.joinKeyColumnName(prop.discriminator, fieldName, fieldNames1.length > 1));
549
549
  prop.fieldNames ??= [prop.discriminatorColumn, ...idColumns];
550
- prop.joinColumns ??= idColumns;
550
+ prop.joinColumns ??= prop.fieldNames.slice(1);
551
551
  prop.referencedColumnNames ??= fieldNames1;
552
552
  prop.referencedTableName ??= prop.targetMeta.tableName;
553
553
  return;
@@ -1174,12 +1174,24 @@ export class MetadataDiscovery {
1174
1174
  if (!prop.discriminator && !prop.discriminatorColumn && !prop.discriminatorMap && !Array.isArray(prop.target)) {
1175
1175
  return;
1176
1176
  }
1177
+ const isToOne = [ReferenceKind.MANY_TO_ONE, ReferenceKind.ONE_TO_ONE].includes(prop.kind);
1178
+ const isUnionTargetMN = prop.kind === ReferenceKind.MANY_TO_MANY && Array.isArray(prop.target);
1177
1179
  prop.polymorphic = true;
1178
1180
  prop.discriminator ??= prop.name;
1181
+ // explicit `fieldNames` use the `[discriminatorColumn, ...fkIdColumns]` layout
1182
+ if (isToOne && prop.fieldNames && prop.fieldNames.length > 1) {
1183
+ prop.discriminatorColumn ??= prop.fieldNames[0];
1184
+ // `EntitySchema` mirrors `fieldNames` into `joinColumns`, let `initManyToOneFields` derive them after embedded prefixing
1185
+ if (Utils.equals(prop.joinColumns, prop.fieldNames)) {
1186
+ delete prop.joinColumns;
1187
+ }
1188
+ }
1179
1189
  prop.discriminatorColumn ??= this.#namingStrategy.discriminatorColumnName(prop.discriminator);
1180
1190
  prop.createForeignKeyConstraint = false;
1181
- const isToOne = [ReferenceKind.MANY_TO_ONE, ReferenceKind.ONE_TO_ONE].includes(prop.kind);
1182
- const isUnionTargetMN = prop.kind === ReferenceKind.MANY_TO_MANY && Array.isArray(prop.target);
1191
+ // a single field name can only be the FK column, e.g. mirrored from `joinColumn`
1192
+ if (isToOne && prop.fieldNames?.length === 1) {
1193
+ prop.fieldNames = [prop.discriminatorColumn, ...prop.fieldNames];
1194
+ }
1183
1195
  if (isToOne || isUnionTargetMN) {
1184
1196
  const types = prop.type.split(/ ?\| ?/);
1185
1197
  prop.polymorphTargets = discovered.filter(m => types.includes(m.className) && !m.embeddable);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/core",
3
- "version": "7.2.2-dev.22",
3
+ "version": "7.2.2-dev.24",
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.2-dev.22';
156
+ static #ORM_VERSION = '7.2.2-dev.24';
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}`;