@mikro-orm/knex 6.0.0-dev.202 → 6.0.0-dev.204

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/knex",
3
- "version": "6.0.0-dev.202",
3
+ "version": "6.0.0-dev.204",
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",
@@ -66,6 +66,6 @@
66
66
  "@mikro-orm/core": "^5.9.2"
67
67
  },
68
68
  "peerDependencies": {
69
- "@mikro-orm/core": "6.0.0-dev.202"
69
+ "@mikro-orm/core": "6.0.0-dev.204"
70
70
  }
71
71
  }
@@ -25,6 +25,7 @@ export declare class CriteriaNode<T extends object> implements ICriteriaNode<T>
25
25
  getPath(addIndex?: boolean): string;
26
26
  private isPivotJoin;
27
27
  getPivotPath(path: string): string;
28
+ aliased(field: string, alias?: string): string;
28
29
  /** @ignore */
29
30
  [inspect.custom](): string;
30
31
  static isCustomExpression(field: string): boolean;
@@ -106,6 +106,9 @@ class CriteriaNode {
106
106
  getPivotPath(path) {
107
107
  return `${path}[pivot]`;
108
108
  }
109
+ aliased(field, alias) {
110
+ return alias ? `${alias}.${field}` : field;
111
+ }
109
112
  /** @ignore */
110
113
  [util_1.inspect.custom]() {
111
114
  const o = {};
@@ -19,8 +19,13 @@ class ObjectCriteriaNode extends CriteriaNode_1.CriteriaNode {
19
19
  if (this.shouldAutoJoin(nestedAlias)) {
20
20
  if (keys.some(k => ['$some', '$none', '$every'].includes(k))) {
21
21
  const $and = [];
22
- const primaryKeys = this.metadata.find(this.entityName).primaryKeys.map(pk => `${alias}.${pk}`);
22
+ const primaryKeys = this.metadata.find(this.entityName).primaryKeys.map(pk => {
23
+ return [enums_1.QueryType.SELECT, enums_1.QueryType.COUNT].includes(qb.type) ? `${alias}.${pk}` : pk;
24
+ });
23
25
  for (const key of keys) {
26
+ if (!['$some', '$none', '$every'].includes(key)) {
27
+ throw new Error('Mixing collection operators with other filters is not allowed.');
28
+ }
24
29
  const payload = this.payload[key].unwrap();
25
30
  const sub = qb.clone(true).innerJoin(this.key, qb.getNextAlias(this.prop.type));
26
31
  sub.select(this.prop.targetMeta.primaryKeys);
@@ -101,7 +106,7 @@ class ObjectCriteriaNode extends CriteriaNode_1.CriteriaNode {
101
106
  if (core_1.Utils.isOperator(k, false)) {
102
107
  const tmp = payload[k];
103
108
  delete payload[k];
104
- o[`${alias}.${field}`] = { [k]: tmp, ...(o[`${alias}.${field}`] || {}) };
109
+ o[this.aliased(field, alias)] = { [k]: tmp, ...(o[this.aliased(field, alias)] || {}) };
105
110
  }
106
111
  else if (this.isPrefixed(k) || core_1.Utils.isOperator(k) || !childAlias) {
107
112
  const idx = prop.referencedPKs.indexOf(k);
@@ -114,7 +119,7 @@ class ObjectCriteriaNode extends CriteriaNode_1.CriteriaNode {
114
119
  }
115
120
  else if (core_1.Utils.isOperator(k) && Array.isArray(payload[k])) {
116
121
  o[key] = payload[k].map((child) => Object.keys(child).reduce((o, childKey) => {
117
- const key = (this.isPrefixed(childKey) || core_1.Utils.isOperator(childKey)) ? childKey : `${childAlias}.${childKey}`;
122
+ const key = (this.isPrefixed(childKey) || core_1.Utils.isOperator(childKey)) ? childKey : this.aliased(childKey, childAlias);
118
123
  o[key] = child[childKey];
119
124
  return o;
120
125
  }, {}));
@@ -128,6 +133,7 @@ class ObjectCriteriaNode extends CriteriaNode_1.CriteriaNode {
128
133
  }
129
134
  else {
130
135
  o[`${childAlias}.${k}`] = payload[k];
136
+ o[this.aliased(k, childAlias)] = payload[k];
131
137
  }
132
138
  }
133
139
  }
@@ -13,7 +13,7 @@ class ScalarCriteriaNode extends CriteriaNode_1.CriteriaNode {
13
13
  const path = this.getPath();
14
14
  const parentPath = this.parent.getPath(); // the parent is always there, otherwise `shouldJoin` would return `false`
15
15
  const nestedAlias = qb.getAliasForJoinPath(path) || qb.getNextAlias(this.prop?.pivotTable ?? this.entityName);
16
- const field = `${options?.alias}.${this.prop.name}`;
16
+ const field = this.aliased(this.prop.name, options?.alias);
17
17
  const type = this.prop.kind === core_1.ReferenceKind.MANY_TO_MANY ? enums_1.JoinType.pivotJoin : enums_1.JoinType.leftJoin;
18
18
  qb.join(field, nestedAlias, undefined, type, path);
19
19
  // select the owner as virtual property when joining from 1:1 inverse side, but only if the parent is root entity