@mikro-orm/core 7.0.13-dev.0 → 7.0.13-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/EntityManager.js +17 -3
- package/package.json +1 -1
- package/utils/Utils.js +1 -1
package/EntityManager.js
CHANGED
|
@@ -1713,8 +1713,13 @@ export class EntityManager {
|
|
|
1713
1713
|
return [];
|
|
1714
1714
|
}
|
|
1715
1715
|
const meta = this.metadata.find(entityName);
|
|
1716
|
-
// infer populate
|
|
1717
|
-
|
|
1716
|
+
// infer populate hints from `fields` when present; merge with explicit `populate` if both are set
|
|
1717
|
+
const fields = options.fields ? this.buildFields(options.fields) : undefined;
|
|
1718
|
+
const populateArray = Array.isArray(options.populate) ? options.populate : undefined;
|
|
1719
|
+
const hasNestedFields = fields?.some(f => f.includes('.')) ?? false;
|
|
1720
|
+
const shouldInfer = fields !== undefined && options.populate === undefined;
|
|
1721
|
+
const shouldMerge = fields !== undefined && populateArray !== undefined && populateArray.length > 0 && hasNestedFields;
|
|
1722
|
+
if (shouldInfer || shouldMerge) {
|
|
1718
1723
|
// we need to prune the `populate` hint from to-one relations, as partially loading them does not require their population, we want just the FK
|
|
1719
1724
|
const pruneToOneRelations = (meta, fields) => {
|
|
1720
1725
|
const ret = [];
|
|
@@ -1748,7 +1753,16 @@ export class EntityManager {
|
|
|
1748
1753
|
}
|
|
1749
1754
|
return Utils.unique(ret);
|
|
1750
1755
|
};
|
|
1751
|
-
|
|
1756
|
+
const fromFields = pruneToOneRelations(meta, fields);
|
|
1757
|
+
if (shouldInfer) {
|
|
1758
|
+
options.populate = fromFields;
|
|
1759
|
+
}
|
|
1760
|
+
else {
|
|
1761
|
+
// with an explicit populate, only nested paths (e.g. `item.id`) need to be merged in — they
|
|
1762
|
+
// require a JOIN to access sub-fields, whereas bare names are already handled by the driver
|
|
1763
|
+
const extras = fromFields.filter(f => f.includes('.'));
|
|
1764
|
+
options.populate = [...populateArray, ...extras];
|
|
1765
|
+
}
|
|
1752
1766
|
}
|
|
1753
1767
|
if (!options.populate) {
|
|
1754
1768
|
const populate = this.#entityLoader.normalizePopulate(entityName, [], options.strategy, true, options.exclude);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/core",
|
|
3
|
-
"version": "7.0.13-dev.
|
|
3
|
+
"version": "7.0.13-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
|
"keywords": [
|
|
6
6
|
"data-mapper",
|
package/utils/Utils.js
CHANGED
|
@@ -141,7 +141,7 @@ export function parseJsonSafe(value) {
|
|
|
141
141
|
/** Collection of general-purpose utility methods used throughout the ORM. */
|
|
142
142
|
export class Utils {
|
|
143
143
|
static PK_SEPARATOR = '~~~';
|
|
144
|
-
static #ORM_VERSION = '7.0.13-dev.
|
|
144
|
+
static #ORM_VERSION = '7.0.13-dev.2';
|
|
145
145
|
/**
|
|
146
146
|
* Checks if the argument is instance of `Object`. Returns false for arrays.
|
|
147
147
|
*/
|