@mikro-orm/knex 6.4.7-dev.9 → 6.4.8-dev.0
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/AbstractSqlDriver.js
CHANGED
|
@@ -254,6 +254,9 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
|
|
|
254
254
|
: meta2.props.filter(prop => this.platform.shouldHaveColumn(prop, hint.children || []));
|
|
255
255
|
const tz = this.platform.getTimezone();
|
|
256
256
|
for (const prop of targetProps) {
|
|
257
|
+
if (prop.fieldNames.every(name => typeof root[`${relationAlias}__${name}`] === 'undefined')) {
|
|
258
|
+
continue;
|
|
259
|
+
}
|
|
257
260
|
if (prop.fieldNames.length > 1) { // composite keys
|
|
258
261
|
const fk = prop.fieldNames.map(name => root[`${relationAlias}__${name}`]);
|
|
259
262
|
const pk = core_1.Utils.mapFlatCompositePrimaryKey(fk, prop);
|
|
@@ -930,11 +933,11 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
|
|
|
930
933
|
getFieldsForJoinedLoad(qb, meta, explicitFields, exclude, populate = [], options, parentTableAlias, parentJoinPath, count) {
|
|
931
934
|
const fields = [];
|
|
932
935
|
const joinedProps = this.joinedProps(meta, populate, options);
|
|
933
|
-
const shouldHaveColumn = (prop, populate, fields) => {
|
|
936
|
+
const shouldHaveColumn = (meta, prop, populate, fields) => {
|
|
934
937
|
if (!this.platform.shouldHaveColumn(prop, populate, exclude)) {
|
|
935
938
|
return false;
|
|
936
939
|
}
|
|
937
|
-
if (!fields || fields.includes('*') || prop.primary) {
|
|
940
|
+
if (!fields || fields.includes('*') || prop.primary || meta.root.discriminatorColumn === prop.name) {
|
|
938
941
|
return true;
|
|
939
942
|
}
|
|
940
943
|
return fields.some(f => f === prop.name || f.toString().startsWith(prop.name + '.'));
|
|
@@ -944,7 +947,7 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
|
|
|
944
947
|
if (parentJoinPath) {
|
|
945
948
|
// alias all fields in the primary table
|
|
946
949
|
meta.props
|
|
947
|
-
.filter(prop => shouldHaveColumn(prop, populate, explicitFields))
|
|
950
|
+
.filter(prop => shouldHaveColumn(meta, prop, populate, explicitFields))
|
|
948
951
|
.forEach(prop => fields.push(...this.mapPropToFieldNames(qb, prop, parentTableAlias)));
|
|
949
952
|
}
|
|
950
953
|
for (const hint of joinedProps) {
|
|
@@ -1281,6 +1284,9 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
|
|
|
1281
1284
|
if (!options.fields.includes('*') && !options.fields.includes(`${qb.alias}.*`)) {
|
|
1282
1285
|
ret.unshift(...meta.primaryKeys.filter(pk => !options.fields.includes(pk)));
|
|
1283
1286
|
}
|
|
1287
|
+
if (meta.root.discriminatorColumn && !options.fields.includes(`${qb.alias}.${meta.root.discriminatorColumn}`)) {
|
|
1288
|
+
ret.push(meta.root.discriminatorColumn);
|
|
1289
|
+
}
|
|
1284
1290
|
}
|
|
1285
1291
|
else if (!core_1.Utils.isEmpty(options.exclude) || lazyProps.some(p => !p.formula && (p.kind !== '1:1' || p.owner))) {
|
|
1286
1292
|
const props = meta.props.filter(prop => this.platform.shouldHaveColumn(prop, populate, options.exclude, false));
|
|
@@ -59,12 +59,15 @@ class MsSqlQueryCompiler extends MonkeyPatchable_1.MonkeyPatchable.MsSqlQueryCom
|
|
|
59
59
|
|| (typeof insert === 'object' && core_1.Utils.isEmpty(insert));
|
|
60
60
|
}
|
|
61
61
|
_mergeOn(conflict) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
const conflictColumn = this.formatter.columnize(conflict[0]);
|
|
65
|
-
sql = `on ${this.tableName}.${conflictColumn} = tsource.${conflictColumn}`;
|
|
62
|
+
if (!Array.isArray(conflict)) {
|
|
63
|
+
return 'on 1=1';
|
|
66
64
|
}
|
|
67
|
-
|
|
65
|
+
const parts = [];
|
|
66
|
+
for (const col of conflict) {
|
|
67
|
+
const conflictColumn = this.formatter.columnize(col);
|
|
68
|
+
parts.push(`${this.tableName}.${conflictColumn} = tsource.${conflictColumn}`);
|
|
69
|
+
}
|
|
70
|
+
return `on ${parts.join(' and ')}`;
|
|
68
71
|
}
|
|
69
72
|
_insertWithMerge() {
|
|
70
73
|
const { insert = [], onConflict, ignore, merge, returning, options = {} } = this.single;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/knex",
|
|
3
|
-
"version": "6.4.
|
|
3
|
+
"version": "6.4.8-dev.0",
|
|
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",
|
|
@@ -63,10 +63,10 @@
|
|
|
63
63
|
"sqlstring": "2.3.3"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
|
-
"@mikro-orm/core": "^6.4.
|
|
66
|
+
"@mikro-orm/core": "^6.4.7"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
69
|
-
"@mikro-orm/core": "6.4.
|
|
69
|
+
"@mikro-orm/core": "6.4.8-dev.0",
|
|
70
70
|
"better-sqlite3": "*",
|
|
71
71
|
"libsql": "*",
|
|
72
72
|
"mariadb": "*"
|
package/query/CriteriaNode.js
CHANGED
|
@@ -72,16 +72,12 @@ class CriteriaNode {
|
|
|
72
72
|
let joinAlias = qb.getAliasForJoinPath(this.getPath());
|
|
73
73
|
if (!joinAlias && this.parent && [core_1.ReferenceKind.MANY_TO_ONE, core_1.ReferenceKind.ONE_TO_ONE].includes(this.prop.kind) && this.prop.owner) {
|
|
74
74
|
joinAlias = qb.getAliasForJoinPath(this.parent.getPath());
|
|
75
|
-
return core_1.Utils.getPrimaryKeyHash(this.prop.
|
|
75
|
+
return core_1.Utils.getPrimaryKeyHash(this.prop.ownColumns.map(col => `${joinAlias ?? qb.alias}.${col}`));
|
|
76
76
|
}
|
|
77
77
|
const alias = joinAlias ?? qb.alias;
|
|
78
78
|
if (this.prop.kind === core_1.ReferenceKind.MANY_TO_MANY) {
|
|
79
79
|
return core_1.Utils.getPrimaryKeyHash(this.prop.inverseJoinColumns.map(col => `${alias}.${col}`));
|
|
80
80
|
}
|
|
81
|
-
// if we found a matching join, we need to use the target table column names, as we use that alias instead of the root
|
|
82
|
-
if (!joinAlias && this.prop.owner && this.prop.joinColumns.length > 1) {
|
|
83
|
-
return core_1.Utils.getPrimaryKeyHash(this.prop.joinColumns.map(col => `${alias}.${col}`));
|
|
84
|
-
}
|
|
85
81
|
return core_1.Utils.getPrimaryKeyHash(this.prop.referencedColumnNames.map(col => `${alias}.${col}`));
|
|
86
82
|
}
|
|
87
83
|
getPath(addIndex = false) {
|
|
@@ -43,9 +43,6 @@ class QueryBuilderHelper {
|
|
|
43
43
|
const prop = this.getProperty(f, a);
|
|
44
44
|
const fkIdx2 = prop?.fieldNames.findIndex(name => name === f) ?? -1;
|
|
45
45
|
if (fkIdx2 !== -1) {
|
|
46
|
-
if (prop?.ownColumns && !prop.ownColumns.includes(f)) {
|
|
47
|
-
continue;
|
|
48
|
-
}
|
|
49
46
|
parts.push(this.mapper(a !== this.alias ? `${a}.${prop.fieldNames[fkIdx2]}` : prop.fieldNames[fkIdx2], type, value, alias));
|
|
50
47
|
}
|
|
51
48
|
else if (prop) {
|
|
@@ -66,9 +63,6 @@ class QueryBuilderHelper {
|
|
|
66
63
|
}
|
|
67
64
|
});
|
|
68
65
|
}
|
|
69
|
-
if (parts.length === 1) {
|
|
70
|
-
return parts[0];
|
|
71
|
-
}
|
|
72
66
|
return this.knex.raw('(' + parts.map(part => this.knex.ref(part)).join(', ') + ')');
|
|
73
67
|
}
|
|
74
68
|
const rawField = core_1.RawQueryFragment.getKnownFragment(field);
|