@mikro-orm/core 7.2.10-dev.9 → 7.2.11-dev.0
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/entity/EntityFactory.js +14 -5
- package/entity/EntityLoader.js +2 -1
- package/package.json +1 -1
- package/utils/Configuration.d.ts +2 -2
- package/utils/Configuration.js +0 -1
- package/utils/Utils.js +1 -1
- package/utils/upsert-utils.js +13 -6
package/entity/EntityFactory.js
CHANGED
|
@@ -4,6 +4,7 @@ import { EventType, ReferenceKind } from '../enums.js';
|
|
|
4
4
|
import { Reference } from './Reference.js';
|
|
5
5
|
import { helper } from './wrap.js';
|
|
6
6
|
import { EntityHelper } from './EntityHelper.js';
|
|
7
|
+
import { PolymorphicRef } from './PolymorphicRef.js';
|
|
7
8
|
import { JsonType } from '../types/JsonType.js';
|
|
8
9
|
import { isRaw } from '../utils/RawQueryFragment.js';
|
|
9
10
|
/** @internal Factory responsible for creating, merging, and hydrating entity instances. */
|
|
@@ -237,12 +238,20 @@ export class EntityFactory {
|
|
|
237
238
|
const nullVal = this.#config.get('forceUndefined') ? undefined : null;
|
|
238
239
|
Utils.keys(diff2).forEach(key => {
|
|
239
240
|
const prop = meta.properties[key];
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
241
|
+
// a joined polymorphic row carries its target class in `constructor`, so it is not a plain object
|
|
242
|
+
const joined = Utils.isPlainObject(data[prop.name]) ||
|
|
243
|
+
(prop.polymorphic && Utils.isObject(data[prop.name]) && !(data[prop.name] instanceof PolymorphicRef));
|
|
244
|
+
if ([ReferenceKind.MANY_TO_ONE, ReferenceKind.ONE_TO_ONE].includes(prop.kind) && joined) {
|
|
245
|
+
const target = entity[prop.name] ? Reference.unwrapReference(entity[prop.name]) : null;
|
|
246
|
+
// use the actual target's meta, a polymorphic relation has several
|
|
247
|
+
let value = target ? EntityHelper.getForeignKeyValue(target, prop, helper(target).__meta) : null;
|
|
248
|
+
if (target && prop.polymorphic) {
|
|
249
|
+
const discriminator = QueryHelper.findDiscriminatorValue(prop.discriminatorMap, target.constructor);
|
|
250
|
+
value = new PolymorphicRef(discriminator, value);
|
|
251
|
+
}
|
|
252
|
+
diff2[key] = value;
|
|
244
253
|
}
|
|
245
|
-
if (!options.convertCustomTypes &&
|
|
254
|
+
else if (!options.convertCustomTypes &&
|
|
246
255
|
[ReferenceKind.MANY_TO_ONE, ReferenceKind.ONE_TO_ONE, ReferenceKind.SCALAR].includes(prop.kind) &&
|
|
247
256
|
prop.customType?.ensureComparable(meta, prop) &&
|
|
248
257
|
diff2[key] != null) {
|
package/entity/EntityLoader.js
CHANGED
|
@@ -730,7 +730,8 @@ export class EntityLoader {
|
|
|
730
730
|
convertCustomTypes: true,
|
|
731
731
|
schema: options.schema ?? this.#em.config.get('schema'),
|
|
732
732
|
});
|
|
733
|
-
|
|
733
|
+
// the factory already registered the snapshot, the raw row is not comparable
|
|
734
|
+
return this.#em.getUnitOfWork().register(entity, undefined, { loaded: true });
|
|
734
735
|
});
|
|
735
736
|
const hasLimit = populate?.limit != null;
|
|
736
737
|
entity[prop.name].hydrate(items, true, hasLimit, hasLimit);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/core",
|
|
3
|
-
"version": "7.2.
|
|
3
|
+
"version": "7.2.11-dev.0",
|
|
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/Configuration.d.ts
CHANGED
|
@@ -961,8 +961,8 @@ export interface Options<Driver extends IDatabaseDriver = IDatabaseDriver, EM ex
|
|
|
961
961
|
};
|
|
962
962
|
/**
|
|
963
963
|
* Metadata provider class for entity discovery.
|
|
964
|
-
* Built-in options: `
|
|
965
|
-
* @default
|
|
964
|
+
* Built-in options: `MetadataProvider` (default), `ReflectMetadataProvider` (from `@mikro-orm/decorators/legacy`), `TsMorphMetadataProvider`.
|
|
965
|
+
* @default MetadataProvider
|
|
966
966
|
* @see https://mikro-orm.io/docs/metadata-providers
|
|
967
967
|
*/
|
|
968
968
|
metadataProvider: {
|
package/utils/Configuration.js
CHANGED
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.
|
|
156
|
+
static #ORM_VERSION = '7.2.11-dev.0';
|
|
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}`;
|
package/utils/upsert-utils.js
CHANGED
|
@@ -155,14 +155,21 @@ export function getWhereCondition(meta, onConflictFields, data, where) {
|
|
|
155
155
|
unique.findIndex(p => data[p] ?? data[p.substring(0, p.indexOf('.'))] != null);
|
|
156
156
|
if (onConflictFields || where == null) {
|
|
157
157
|
if (propIndex !== false && propIndex >= 0) {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
158
|
+
// `onConflictFields` form one composite key, while the unique props are each unique on their own
|
|
159
|
+
const keys = onConflictFields
|
|
160
|
+
? unique.filter(p => (data[p] ?? data[p.substring(0, p.indexOf('.'))]) != null)
|
|
161
|
+
: [unique[propIndex]];
|
|
162
|
+
where = {};
|
|
163
|
+
for (const field of keys) {
|
|
164
|
+
let key = field;
|
|
165
|
+
if (key.includes('.')) {
|
|
166
|
+
const prop = meta.properties[key.substring(0, key.indexOf('.'))];
|
|
167
|
+
if (prop) {
|
|
168
|
+
key = `${prop.fieldNames[0]}${key.substring(key.indexOf('.'))}`;
|
|
169
|
+
}
|
|
163
170
|
}
|
|
171
|
+
where[key] = getPropertyValue(data, field);
|
|
164
172
|
}
|
|
165
|
-
where = { [key]: getPropertyValue(data, unique[propIndex]) };
|
|
166
173
|
}
|
|
167
174
|
else {
|
|
168
175
|
for (const u of uniques) {
|