@mikro-orm/core 7.2.9-dev.13 → 7.2.9-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.
@@ -87,6 +87,8 @@ export declare abstract class DatabaseDriver<C extends Connection> implements ID
87
87
  mapDataToFieldNames(data: Dictionary, stringifyJsonArrays: boolean, properties?: Record<string, EntityProperty>, convertCustomTypes?: boolean, object?: boolean): Dictionary;
88
88
  protected inlineEmbeddables<T extends object>(meta: EntityMetadata<T>, data: T, where?: boolean): void;
89
89
  protected getPrimaryKeyFields<T>(meta: EntityMetadata<T>): string[];
90
+ /** Column a scalar value of the property maps to; a composite FK given as a scalar holds only the target PK, which belongs to the column referencing it. */
91
+ protected getScalarFieldName(prop: EntityProperty): string;
90
92
  protected createReplicas(cb: (c: ConnectionOptions) => C): C[];
91
93
  /** Acquires a pessimistic lock on the given entity. */
92
94
  lockPessimistic<T extends object>(entity: T, options: LockOptions): Promise<void>;
@@ -511,7 +511,7 @@ export class DatabaseDriver {
511
511
  data[k] = raw(sql.replace(/\?/g, '\\?'));
512
512
  }
513
513
  if (prop.fieldNames) {
514
- Utils.renameKey(data, k, prop.fieldNames[0]);
514
+ Utils.renameKey(data, k, this.getScalarFieldName(prop));
515
515
  }
516
516
  });
517
517
  return data;
@@ -580,6 +580,14 @@ export class DatabaseDriver {
580
580
  getPrimaryKeyFields(meta) {
581
581
  return meta.getPrimaryProps().flatMap(pk => pk.fieldNames);
582
582
  }
583
+ /** Column a scalar value of the property maps to; a composite FK given as a scalar holds only the target PK, which belongs to the column referencing it. */
584
+ getScalarFieldName(prop) {
585
+ if (prop.fieldNames.length < 2 || prop.polymorphic || !prop.targetMeta) {
586
+ return prop.fieldNames[0];
587
+ }
588
+ const idx = prop.referencedColumnNames.indexOf(prop.targetMeta.getPrimaryProps()[0]?.fieldNames[0]);
589
+ return prop.fieldNames[idx === -1 ? 0 : idx];
590
+ }
583
591
  createReplicas(cb) {
584
592
  const replicas = this.config.get('replicas', []);
585
593
  const ret = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/core",
3
- "version": "7.2.9-dev.13",
3
+ "version": "7.2.9-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.9-dev.13';
156
+ static #ORM_VERSION = '7.2.9-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}`;