@mikro-orm/core 7.2.9-dev.21 → 7.2.9-dev.23

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/core",
3
- "version": "7.2.9-dev.21",
3
+ "version": "7.2.9-dev.23",
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",
@@ -4,6 +4,7 @@ import { ChangeSet, ChangeSetType } from './ChangeSet.js';
4
4
  import { helper } from '../entity/wrap.js';
5
5
  import { validateEntity } from '../entity/validators.js';
6
6
  import { Reference } from '../entity/Reference.js';
7
+ import { EntityHelper } from '../entity/EntityHelper.js';
7
8
  import { PolymorphicRef } from '../entity/PolymorphicRef.js';
8
9
  import { ReferenceKind } from '../enums.js';
9
10
  import { isRaw } from '../utils/RawQueryFragment.js';
@@ -172,14 +173,10 @@ export class ChangeSetComputer {
172
173
  if (!prop.targetKey && !target.__helper.__initialized) {
173
174
  throw ValidationError.referenceWithoutPK(target);
174
175
  }
175
- let value = prop.targetKey ? target[prop.targetKey] : target.__helper.__identifier;
176
176
  // use the actual target's meta, a polymorphic relation has several
177
- if (prop.targetKey) {
178
- const targetProp = target.__meta.properties[prop.targetKey];
179
- if (targetProp?.customType) {
180
- value = targetProp.customType.convertToDatabaseValue(value, this.#platform, { mode: 'serialization' });
181
- }
182
- }
177
+ let value = prop.targetKey
178
+ ? EntityHelper.getForeignKeyValue(target, prop, target.__meta)
179
+ : target.__helper.__identifier;
183
180
  if (prop.polymorphic) {
184
181
  const discriminator = QueryHelper.findDiscriminatorValue(prop.discriminatorMap, target.constructor);
185
182
  value = new PolymorphicRef(discriminator, value);
@@ -6,6 +6,7 @@ import { JsonType } from '../types/JsonType.js';
6
6
  import { Raw } from './RawQueryFragment.js';
7
7
  import { EntityIdentifier } from '../entity/EntityIdentifier.js';
8
8
  import { PolymorphicRef } from '../entity/PolymorphicRef.js';
9
+ import { EntityHelper } from '../entity/EntityHelper.js';
9
10
  /** @internal Generates and caches JIT-compiled functions for comparing, snapshotting, and mapping entity data. */
10
11
  export class EntityComparator {
11
12
  #comparators = new Map();
@@ -663,15 +664,8 @@ export class EntityComparator {
663
664
  ret += ` }\n`;
664
665
  if (prop.targetKey) {
665
666
  // the FK holds the `targetKey` value in the format of the actual target's column
666
- const targetKey = prop.targetKey;
667
667
  const targetKeyValueKey = `targetKeyValue_${this.safeKey(prop.name)}`;
668
- context.set(targetKeyValueKey, (val) => {
669
- const customType = val.__meta.properties[targetKey]?.customType;
670
- const value = val[targetKey];
671
- return customType
672
- ? customType.convertToDatabaseValue(value, this.#platform, { mode: 'serialization' })
673
- : value;
674
- });
668
+ context.set(targetKeyValueKey, (val) => EntityHelper.getForeignKeyValue(val, prop, val.__meta));
675
669
  ret += ` const pk = ${targetKeyValueKey}(val${level});\n`;
676
670
  }
677
671
  else {
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.21';
156
+ static #ORM_VERSION = '7.2.9-dev.23';
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}`;