@mikro-orm/core 7.1.1-dev.1 → 7.1.1-dev.11
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 +6 -4
- package/package.json +1 -1
- package/utils/QueryHelper.js +12 -1
- package/utils/Utils.js +1 -1
package/EntityManager.js
CHANGED
|
@@ -863,7 +863,7 @@ export class EntityManager {
|
|
|
863
863
|
}
|
|
864
864
|
}
|
|
865
865
|
const data2 = await this.driver.findOne(meta.class, where, {
|
|
866
|
-
fields: returning,
|
|
866
|
+
fields: returning.concat(...(options.onConflictMergeFields ?? [])),
|
|
867
867
|
ctx: em.#transactionContext,
|
|
868
868
|
convertCustomTypes: true,
|
|
869
869
|
connectionType: 'write',
|
|
@@ -1031,11 +1031,12 @@ export class EntityManager {
|
|
|
1031
1031
|
entities.set(entity, row);
|
|
1032
1032
|
entitiesByData.set(row, entity);
|
|
1033
1033
|
});
|
|
1034
|
-
// skip
|
|
1034
|
+
// skip the reload only when RETURNING brought back a row for every input
|
|
1035
|
+
// (onConflictWhere can suppress writes, leaving some rows out)
|
|
1035
1036
|
// oxfmt-ignore
|
|
1036
1037
|
const uniqueFields = options.onConflictFields ?? (Utils.isPlainObject(allWhere[0]) ? Object.keys(allWhere[0]).flatMap(key => Utils.splitPrimaryKeys(key)) : meta.primaryKeys);
|
|
1037
1038
|
const returning = getOnConflictReturningFields(meta, data[0], uniqueFields, options);
|
|
1038
|
-
const reloadFields = returning.length > 0 && !(this.getPlatform().usesReturningStatement() && res.rows?.length);
|
|
1039
|
+
const reloadFields = returning.length > 0 && !(this.getPlatform().usesReturningStatement() && res.rows?.length === data.length);
|
|
1039
1040
|
if (options.onConflictAction === 'ignore' || (!res.rows?.length && loadPK.size > 0) || reloadFields) {
|
|
1040
1041
|
const unique = meta.hydrateProps.filter(p => !p.lazy).map(p => p.name);
|
|
1041
1042
|
const add = new Set(propIndex !== false && propIndex >= 0
|
|
@@ -1055,7 +1056,8 @@ export class EntityManager {
|
|
|
1055
1056
|
const data2 = await this.driver.find(meta.class, where, {
|
|
1056
1057
|
fields: returning
|
|
1057
1058
|
.concat(...add)
|
|
1058
|
-
.concat(...(Array.isArray(uniqueFields) ? uniqueFields : []))
|
|
1059
|
+
.concat(...(Array.isArray(uniqueFields) ? uniqueFields : []))
|
|
1060
|
+
.concat(...(options.onConflictMergeFields ?? [])),
|
|
1059
1061
|
ctx: em.#transactionContext,
|
|
1060
1062
|
convertCustomTypes: true,
|
|
1061
1063
|
connectionType: 'write',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/core",
|
|
3
|
-
"version": "7.1.1-dev.
|
|
3
|
+
"version": "7.1.1-dev.11",
|
|
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/QueryHelper.js
CHANGED
|
@@ -145,8 +145,19 @@ export class QueryHelper {
|
|
|
145
145
|
})));
|
|
146
146
|
}
|
|
147
147
|
Object.keys(where).forEach(k => {
|
|
148
|
-
const
|
|
148
|
+
const prop = meta.properties[k];
|
|
149
|
+
const meta2 = metadata.find(prop?.targetMeta?.class) || meta;
|
|
149
150
|
if (this.inlinePrimaryKeyObjects(where[k], meta2, metadata, k)) {
|
|
151
|
+
// Skip the PK collapse when an owning M:1/1:1 relation's FK column count does not match
|
|
152
|
+
// the target's PK column count (e.g. FK references target PK + an extra unique column).
|
|
153
|
+
// The criteria layer would otherwise emit a malformed predicate such as
|
|
154
|
+
// `(joinCol1, joinCol2) = scalar`. Limited to owning relations — `joinColumns` on the
|
|
155
|
+
// inverse side (1:m) describes the owning entity's FK columns, not the LHS tuple.
|
|
156
|
+
if (prop?.owner &&
|
|
157
|
+
[ReferenceKind.MANY_TO_ONE, ReferenceKind.ONE_TO_ONE].includes(prop.kind) &&
|
|
158
|
+
prop.joinColumns.length !== meta2.primaryKeys.length) {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
150
161
|
where[k] = Utils.getPrimaryKeyValues(where[k], meta2, true);
|
|
151
162
|
}
|
|
152
163
|
});
|
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.1.1-dev.
|
|
144
|
+
static #ORM_VERSION = '7.1.1-dev.11';
|
|
145
145
|
/**
|
|
146
146
|
* Checks if the argument is instance of `Object`. Returns false for arrays.
|
|
147
147
|
*/
|