@mikro-orm/core 7.2.13-dev.3 → 7.2.13-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/package.json +1 -1
- package/unit-of-work/UnitOfWork.js +14 -0
- package/utils/EntityComparator.js +2 -1
- package/utils/Utils.js +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/core",
|
|
3
|
-
"version": "7.2.13-dev.
|
|
3
|
+
"version": "7.2.13-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
|
"keywords": [
|
|
6
6
|
"data-mapper",
|
|
@@ -3,11 +3,13 @@ import { EntityHelper } from '../entity/EntityHelper.js';
|
|
|
3
3
|
import { helper } from '../entity/wrap.js';
|
|
4
4
|
import { Reference } from '../entity/Reference.js';
|
|
5
5
|
import { EntityIdentifier } from '../entity/EntityIdentifier.js';
|
|
6
|
+
import { PolymorphicRef } from '../entity/PolymorphicRef.js';
|
|
6
7
|
import { ChangeSet, ChangeSetType } from './ChangeSet.js';
|
|
7
8
|
import { ChangeSetComputer } from './ChangeSetComputer.js';
|
|
8
9
|
import { ChangeSetPersister } from './ChangeSetPersister.js';
|
|
9
10
|
import { CommitOrderCalculator } from './CommitOrderCalculator.js';
|
|
10
11
|
import { Utils } from '../utils/Utils.js';
|
|
12
|
+
import { QueryHelper } from '../utils/QueryHelper.js';
|
|
11
13
|
import { Cascade, DeferMode, EventType, LockMode, ReferenceKind } from '../enums.js';
|
|
12
14
|
import { OptimisticLockError, ValidationError } from '../errors.js';
|
|
13
15
|
import { TransactionEventBroadcaster } from '../events/TransactionEventBroadcaster.js';
|
|
@@ -97,6 +99,18 @@ export class UnitOfWork {
|
|
|
97
99
|
: Utils.getPrimaryKeyValues(data[prop.name], prop.targetMeta, true);
|
|
98
100
|
}
|
|
99
101
|
}
|
|
102
|
+
else if ([ReferenceKind.MANY_TO_ONE, ReferenceKind.ONE_TO_ONE].includes(prop.kind) &&
|
|
103
|
+
prop.polymorphic &&
|
|
104
|
+
Utils.isObject(data[prop.name]) &&
|
|
105
|
+
Object.hasOwn(data[prop.name], 'constructor')) {
|
|
106
|
+
// a joined polymorphic row carries its target class in an own `constructor` property
|
|
107
|
+
const row = data[prop.name];
|
|
108
|
+
const discriminator = QueryHelper.findDiscriminatorValue(prop.discriminatorMap, row.constructor);
|
|
109
|
+
const id = prop.targetKey
|
|
110
|
+
? row[prop.targetKey]
|
|
111
|
+
: Utils.getPrimaryKeyValues(row, this.#metadata.get(row.constructor), true);
|
|
112
|
+
data[prop.name] = new PolymorphicRef(discriminator, id);
|
|
113
|
+
}
|
|
100
114
|
else if (prop.kind === ReferenceKind.EMBEDDED && !prop.object && Utils.isPlainObject(data[prop.name])) {
|
|
101
115
|
for (const p of prop.targetMeta.props) {
|
|
102
116
|
/* v8 ignore next */
|
|
@@ -781,7 +781,8 @@ export class EntityComparator {
|
|
|
781
781
|
}
|
|
782
782
|
}
|
|
783
783
|
}
|
|
784
|
-
|
|
784
|
+
// a polymorphic relation is snapshotted as a `PolymorphicRef`, regardless of the custom type of its target PKs
|
|
785
|
+
if (prop.customType && !prop.polymorphic) {
|
|
785
786
|
if (prop.customType.compareValues) {
|
|
786
787
|
const idx = this.#tmpIndex++;
|
|
787
788
|
context.set(`compareValues_${idx}`, (a, b) => {
|
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.13-dev.
|
|
156
|
+
static #ORM_VERSION = '7.2.13-dev.4';
|
|
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}`;
|