@mikro-orm/core 7.2.13-dev.2 → 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/entity/Collection.js
CHANGED
|
@@ -96,12 +96,13 @@ export class Collection {
|
|
|
96
96
|
return (this.#count = this.length);
|
|
97
97
|
}
|
|
98
98
|
let count;
|
|
99
|
+
let cond = this.property.where ? { $and: [where ?? {}, this.property.where] } : where;
|
|
99
100
|
if (dataloader ?? [DataloaderType.ALL, DataloaderType.COLLECTION].includes(em.config.getDataloaderType())) {
|
|
100
101
|
const loader = await em.getDataLoader('count');
|
|
101
|
-
count = await loader.load([this, { where, ...countOptions }]);
|
|
102
|
+
count = await loader.load([this, { where: cond, ...countOptions }]);
|
|
102
103
|
}
|
|
103
104
|
else {
|
|
104
|
-
|
|
105
|
+
cond = this.createLoadCountCondition(cond ?? {});
|
|
105
106
|
count = await em.count(this.property.targetMeta.class, cond, countOptions);
|
|
106
107
|
}
|
|
107
108
|
if (!where) {
|
|
@@ -133,7 +134,7 @@ export class Collection {
|
|
|
133
134
|
items = (await em.find(this.property.targetMeta.class, this.createCondition(where), opts));
|
|
134
135
|
}
|
|
135
136
|
if (options.store) {
|
|
136
|
-
this.hydrate(items, true);
|
|
137
|
+
this.hydrate(items, true, undefined, undefined, false);
|
|
137
138
|
this.setSerializationContext(options);
|
|
138
139
|
this.populated();
|
|
139
140
|
this.#readonly = true;
|
|
@@ -494,7 +495,7 @@ export class Collection {
|
|
|
494
495
|
this.#initialized = true;
|
|
495
496
|
this.#partial = !!partial;
|
|
496
497
|
this.#items.clear();
|
|
497
|
-
this.#count = count ? 0 : undefined;
|
|
498
|
+
this.#count = count && !partial ? 0 : undefined;
|
|
498
499
|
// loaded items are not persisted, that would queue an auto-flush of their type on a read-only path
|
|
499
500
|
const unwrapped = items.map(i => Reference.unwrapReference(i));
|
|
500
501
|
this.addItems(unwrapped, hydration);
|
package/entity/EntityLoader.js
CHANGED
|
@@ -734,7 +734,7 @@ export class EntityLoader {
|
|
|
734
734
|
return this.#em.getUnitOfWork().register(entity, undefined, { loaded: true });
|
|
735
735
|
});
|
|
736
736
|
const hasLimit = populate?.limit != null;
|
|
737
|
-
entity[prop.name].hydrate(items, true, hasLimit, hasLimit);
|
|
737
|
+
entity[prop.name].hydrate(items, true, hasLimit, hasLimit, Utils.isEmpty(where));
|
|
738
738
|
children.push(items);
|
|
739
739
|
}
|
|
740
740
|
return children;
|
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",
|
package/platforms/Platform.js
CHANGED
|
@@ -443,7 +443,7 @@ export class Platform {
|
|
|
443
443
|
}
|
|
444
444
|
getJsonValueType(value) {
|
|
445
445
|
if (Array.isArray(value)) {
|
|
446
|
-
return typeof value
|
|
446
|
+
return typeof value.find(v => v !== null);
|
|
447
447
|
}
|
|
448
448
|
if (Utils.isPlainObject(value) && Object.keys(value).every(k => Utils.isOperator(k))) {
|
|
449
449
|
return this.getJsonValueType(Object.values(value)[0]);
|
|
@@ -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 */
|
package/utils/DataloaderUtils.js
CHANGED
|
@@ -281,7 +281,8 @@ export class DataloaderUtils {
|
|
|
281
281
|
const { where, ...countOpts } = group.opts;
|
|
282
282
|
const conditions = [{ [group.fkProp]: { $in: allPKs } }];
|
|
283
283
|
if (where) {
|
|
284
|
-
|
|
284
|
+
// for M:N the query targets the pivot entity, so the condition goes through its target relation
|
|
285
|
+
conditions.push(group.targetFilterProp ? { [group.targetFilterProp]: where } : where);
|
|
285
286
|
}
|
|
286
287
|
// For M:N, apply the target entity's filters through the pivot's target relation
|
|
287
288
|
if (group.targetFilterProp) {
|
|
@@ -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}`;
|