@mikro-orm/core 6.3.11-dev.1 → 6.3.11-dev.2
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 +10 -6
- package/package.json +2 -2
package/entity/EntityLoader.js
CHANGED
|
@@ -26,11 +26,12 @@ class EntityLoader {
|
|
|
26
26
|
if (entities.length === 0 || Utils_1.Utils.isEmpty(populate)) {
|
|
27
27
|
return this.setSerializationContext(entities, populate, options);
|
|
28
28
|
}
|
|
29
|
+
const meta = this.metadata.find(entityName);
|
|
29
30
|
if (entities.some(e => !e.__helper)) {
|
|
30
31
|
const entity = entities.find(e => !Utils_1.Utils.isEntity(e));
|
|
31
|
-
const meta = this.metadata.find(entityName);
|
|
32
32
|
throw errors_1.ValidationError.notDiscoveredEntity(entity, meta, 'populate');
|
|
33
33
|
}
|
|
34
|
+
const references = entities.filter(e => !(0, wrap_1.helper)(e).isInitialized());
|
|
34
35
|
const visited = options.visited ??= new Set();
|
|
35
36
|
options.where ??= {};
|
|
36
37
|
options.orderBy ??= {};
|
|
@@ -39,6 +40,9 @@ class EntityLoader {
|
|
|
39
40
|
options.validate ??= true;
|
|
40
41
|
options.refresh ??= false;
|
|
41
42
|
options.convertCustomTypes ??= true;
|
|
43
|
+
if (references.length > 0) {
|
|
44
|
+
await this.populateScalar(meta, references, options);
|
|
45
|
+
}
|
|
42
46
|
populate = this.normalizePopulate(entityName, populate, options.strategy, options.lookup);
|
|
43
47
|
const invalid = populate.find(({ field }) => !this.em.canPopulate(entityName, field));
|
|
44
48
|
/* istanbul ignore next */
|
|
@@ -121,7 +125,7 @@ class EntityLoader {
|
|
|
121
125
|
if (prop.kind === enums_1.ReferenceKind.MANY_TO_MANY && prop.owner && !this.driver.getPlatform().usesPivotTable()) {
|
|
122
126
|
const filtered = entities.filter(e => !e[prop.name]?.isInitialized());
|
|
123
127
|
if (filtered.length > 0) {
|
|
124
|
-
await this.populateScalar(meta, filtered, options, prop);
|
|
128
|
+
await this.populateScalar(meta, filtered, { ...options, fields: [prop.name] });
|
|
125
129
|
}
|
|
126
130
|
}
|
|
127
131
|
if (prop.kind === enums_1.ReferenceKind.SCALAR && prop.lazy) {
|
|
@@ -129,7 +133,7 @@ class EntityLoader {
|
|
|
129
133
|
if (options.ignoreLazyScalarProperties || filtered.length === 0) {
|
|
130
134
|
return entities;
|
|
131
135
|
}
|
|
132
|
-
await this.populateScalar(meta, filtered, options, prop);
|
|
136
|
+
await this.populateScalar(meta, filtered, { ...options, fields: [prop.name] });
|
|
133
137
|
return entities;
|
|
134
138
|
}
|
|
135
139
|
if (prop.kind === enums_1.ReferenceKind.EMBEDDED) {
|
|
@@ -147,14 +151,14 @@ class EntityLoader {
|
|
|
147
151
|
this.initializeCollections(filtered, prop, field, data, innerOrderBy.length > 0);
|
|
148
152
|
return data;
|
|
149
153
|
}
|
|
150
|
-
async populateScalar(meta, filtered, options
|
|
154
|
+
async populateScalar(meta, filtered, options) {
|
|
151
155
|
const pk = Utils_1.Utils.getPrimaryKeyHash(meta.primaryKeys);
|
|
152
156
|
const ids = Utils_1.Utils.unique(filtered.map(e => Utils_1.Utils.getPrimaryKeyValues(e, meta.primaryKeys, true)));
|
|
153
157
|
const where = this.mergePrimaryCondition(ids, pk, options, meta, this.metadata, this.driver.getPlatform());
|
|
154
|
-
const { filters, convertCustomTypes, lockMode, strategy, populateWhere, connectionType, logging } = options;
|
|
158
|
+
const { filters, convertCustomTypes, lockMode, strategy, populateWhere, connectionType, logging, fields } = options;
|
|
155
159
|
await this.em.find(meta.className, where, {
|
|
156
160
|
filters, convertCustomTypes, lockMode, strategy, populateWhere, connectionType, logging,
|
|
157
|
-
fields:
|
|
161
|
+
fields: fields,
|
|
158
162
|
populate: [],
|
|
159
163
|
});
|
|
160
164
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/core",
|
|
3
|
-
"version": "6.3.11-dev.
|
|
3
|
+
"version": "6.3.11-dev.2",
|
|
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.11-dev.
|
|
67
|
+
"mikro-orm": "6.3.11-dev.2",
|
|
68
68
|
"reflect-metadata": "0.2.2"
|
|
69
69
|
}
|
|
70
70
|
}
|