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

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.
@@ -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.3",
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.3",
68
68
  "reflect-metadata": "0.2.2"
69
69
  }
70
70
  }