@mikro-orm/core 6.3.7-dev.2 → 6.3.7-dev.4

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/EntityManager.js CHANGED
@@ -1446,25 +1446,25 @@ class EntityManager {
1446
1446
  * Checks whether this EntityManager is currently operating inside a database transaction.
1447
1447
  */
1448
1448
  isInTransaction() {
1449
- return !!this.transactionContext;
1449
+ return !!this.getContext(false).transactionContext;
1450
1450
  }
1451
1451
  /**
1452
1452
  * Gets the transaction context (driver dependent object used to make sure queries are executed on same connection).
1453
1453
  */
1454
1454
  getTransactionContext() {
1455
- return this.transactionContext;
1455
+ return this.getContext(false).transactionContext;
1456
1456
  }
1457
1457
  /**
1458
1458
  * Sets the transaction context.
1459
1459
  */
1460
1460
  setTransactionContext(ctx) {
1461
- this.transactionContext = ctx;
1461
+ this.getContext(false).transactionContext = ctx;
1462
1462
  }
1463
1463
  /**
1464
1464
  * Resets the transaction context.
1465
1465
  */
1466
1466
  resetTransactionContext() {
1467
- delete this.transactionContext;
1467
+ delete this.getContext(false).transactionContext;
1468
1468
  }
1469
1469
  /**
1470
1470
  * Gets the `MetadataStorage` (without parameters) or `EntityMetadata` instance when provided with the `entityName` parameter.
@@ -190,14 +190,13 @@ class EntityFactory {
190
190
  if (!meta.class) {
191
191
  throw new Error(`Cannot create entity ${meta.className}, class prototype is unknown`);
192
192
  }
193
- options.initialized = options.newEntity || options.initialized;
194
193
  const params = this.extractConstructorParams(meta, data, options);
195
194
  const Entity = meta.class;
196
195
  // creates new instance via constructor as this is the new entity
197
196
  const entity = new Entity(...params);
198
197
  // creating managed entity instance when `forceEntityConstructor` is enabled,
199
198
  // we need to wipe all the values as they would cause update queries on next flush
200
- if (!options.initialized && this.config.get('forceEntityConstructor')) {
199
+ if (!options.newEntity && (meta.forceConstructor || this.config.get('forceEntityConstructor'))) {
201
200
  meta.props
202
201
  .filter(prop => prop.persist !== false && !prop.primary && data[prop.name] === undefined)
203
202
  .forEach(prop => delete entity[prop.name]);
@@ -302,7 +301,12 @@ class EntityFactory {
302
301
  const tmp = { ...data };
303
302
  for (const prop of meta.props) {
304
303
  if (options.convertCustomTypes && prop.customType && tmp[prop.name] != null) {
305
- tmp[prop.name] = prop.customType.convertToJSValue(tmp[prop.name], this.platform);
304
+ if ([enums_1.ReferenceKind.MANY_TO_ONE, enums_1.ReferenceKind.ONE_TO_ONE].includes(prop.kind) && Utils_1.Utils.isPlainObject(tmp[prop.name]) && !Utils_1.Utils.extractPK(tmp[prop.name], meta.properties[prop.name].targetMeta, true)) {
305
+ tmp[prop.name] = Reference_1.Reference.wrapReference(this.create(meta.properties[prop.name].type, tmp[prop.name], options), prop);
306
+ }
307
+ else {
308
+ tmp[prop.name] = prop.customType.convertToJSValue(tmp[prop.name], this.platform);
309
+ }
306
310
  }
307
311
  }
308
312
  return tmp;
@@ -446,7 +446,7 @@ class MetadataDiscovery {
446
446
  if (pks.length === 1 && pks[0].kind !== enums_1.ReferenceKind.SCALAR) {
447
447
  pks[0].deleteRule ??= 'cascade';
448
448
  }
449
- meta.forceConstructor = this.shouldForceConstructorUsage(meta);
449
+ meta.forceConstructor ??= this.shouldForceConstructorUsage(meta);
450
450
  this.validator.validateEntityDefinition(this.metadata, meta.className, this.config.get('discovery'));
451
451
  for (const prop of Object.values(meta.properties)) {
452
452
  this.initNullability(prop);
@@ -1264,7 +1264,7 @@ class MetadataDiscovery {
1264
1264
  if (Array.isArray(forceConstructor)) {
1265
1265
  return forceConstructor.some(cls => Utils_1.Utils.className(cls) === meta.className);
1266
1266
  }
1267
- return meta.forceConstructor = forceConstructor;
1267
+ return forceConstructor;
1268
1268
  }
1269
1269
  }
1270
1270
  exports.MetadataDiscovery = MetadataDiscovery;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/core",
3
- "version": "6.3.7-dev.2",
3
+ "version": "6.3.7-dev.4",
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
  "main": "index.js",
6
6
  "module": "index.mjs",
@@ -64,7 +64,7 @@
64
64
  "esprima": "4.0.1",
65
65
  "fs-extra": "11.2.0",
66
66
  "globby": "11.1.0",
67
- "mikro-orm": "6.3.7-dev.2",
67
+ "mikro-orm": "6.3.7-dev.4",
68
68
  "reflect-metadata": "0.2.2"
69
69
  }
70
70
  }