@mikro-orm/core 7.2.9 → 7.2.10-dev.1
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/EntityLoader.js +42 -0
- package/package.json +1 -1
- package/utils/Utils.js +1 -1
package/entity/EntityLoader.js
CHANGED
|
@@ -545,7 +545,49 @@ export class EntityLoader {
|
|
|
545
545
|
return;
|
|
546
546
|
}
|
|
547
547
|
options = { ...options, filters: QueryHelper.mergePropertyFilters(prop.filters, options.filters) };
|
|
548
|
+
// collections with unflushed changes, their items would be lost when reloading
|
|
549
|
+
const dirty = options.refresh
|
|
550
|
+
? []
|
|
551
|
+
: entities
|
|
552
|
+
.map(e => e[field])
|
|
553
|
+
.filter(coll => Utils.isCollection(coll) && coll.isDirty())
|
|
554
|
+
.map(coll => [coll, coll.getItems(false), coll.getSnapshot()]);
|
|
555
|
+
// grouped by type, as a polymorphic collection can hold references of several entity types
|
|
556
|
+
const references = new Map();
|
|
557
|
+
for (const [, items] of populate.field.includes(':') ? [] : dirty) {
|
|
558
|
+
for (const item of items.filter(i => !helper(i).__initialized)) {
|
|
559
|
+
const group = references.get(helper(item).__meta) ?? [];
|
|
560
|
+
group.push(item);
|
|
561
|
+
references.set(helper(item).__meta, group);
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
// loading the references directly keeps an initialized collection from being reloaded
|
|
565
|
+
for (const [meta, items] of references) {
|
|
566
|
+
await this.populateScalar(meta, items, {
|
|
567
|
+
...options,
|
|
568
|
+
where: {},
|
|
569
|
+
populateWhere: undefined,
|
|
570
|
+
fields: this.buildFields(options.fields, prop),
|
|
571
|
+
});
|
|
572
|
+
}
|
|
548
573
|
const populated = await this.populateMany(entityName, entities, populate, options);
|
|
574
|
+
for (const [coll, items, snapshot] of dirty) {
|
|
575
|
+
// partially loaded collections can be readonly
|
|
576
|
+
if (coll.isPartial()) {
|
|
577
|
+
continue;
|
|
578
|
+
}
|
|
579
|
+
const kept = new Set(items);
|
|
580
|
+
// only the diff against the snapshot is restored, a missing snapshot means the collection was overridden via `set()`
|
|
581
|
+
const known = snapshot && new Set(snapshot);
|
|
582
|
+
const lost = items.filter(item => !coll.contains(item, false) && !known?.has(item));
|
|
583
|
+
const removed = coll.getItems(false).filter(item => !kept.has(item) && (!known || known.has(item)));
|
|
584
|
+
if (lost.length > 0) {
|
|
585
|
+
coll.add(lost);
|
|
586
|
+
}
|
|
587
|
+
if (removed.length > 0) {
|
|
588
|
+
coll.remove(removed);
|
|
589
|
+
}
|
|
590
|
+
}
|
|
549
591
|
if (!populate.children && !populate.all) {
|
|
550
592
|
return;
|
|
551
593
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/core",
|
|
3
|
-
"version": "7.2.
|
|
3
|
+
"version": "7.2.10-dev.1",
|
|
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/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.10-dev.1';
|
|
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}`;
|