@mikro-orm/knex 6.5.2-dev.2 → 6.5.2-dev.4

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.5.2-dev.2",
3
+ "version": "6.5.2-dev.4",
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,7 +66,7 @@
66
66
  "@mikro-orm/core": "^6.5.1"
67
67
  },
68
68
  "peerDependencies": {
69
- "@mikro-orm/core": "6.5.2-dev.2",
69
+ "@mikro-orm/core": "6.5.2-dev.4",
70
70
  "better-sqlite3": "*",
71
71
  "libsql": "*",
72
72
  "mariadb": "*"
@@ -20,7 +20,7 @@ export declare class CriteriaNode<T extends object> implements ICriteriaNode<T>
20
20
  shouldInline(payload: any): boolean;
21
21
  willAutoJoin(qb: IQueryBuilder<T>, alias?: string, options?: ICriteriaNodeProcessOptions): boolean;
22
22
  shouldRename(payload: any): boolean;
23
- renameFieldToPK<T>(qb: IQueryBuilder<T>): string;
23
+ renameFieldToPK<T>(qb: IQueryBuilder<T>, ownerAlias?: string): string;
24
24
  getPath(addIndex?: boolean): string;
25
25
  private isPivotJoin;
26
26
  getPivotPath(path: string): string;
@@ -68,13 +68,13 @@ class CriteriaNode {
68
68
  default: return false;
69
69
  }
70
70
  }
71
- renameFieldToPK(qb) {
72
- let joinAlias = qb.getAliasForJoinPath(this.getPath(), { matchPopulateJoins: true });
71
+ renameFieldToPK(qb, ownerAlias) {
72
+ const joinAlias = qb.getAliasForJoinPath(this.getPath(), { matchPopulateJoins: true });
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
- joinAlias = qb.getAliasForJoinPath(this.parent.getPath());
75
- return core_1.Utils.getPrimaryKeyHash(this.prop.joinColumns.map(col => `${joinAlias ?? qb.alias}.${col}`));
74
+ const alias = qb.getAliasForJoinPath(this.parent.getPath()) ?? ownerAlias ?? qb.alias;
75
+ return core_1.Utils.getPrimaryKeyHash(this.prop.joinColumns.map(col => `${alias}.${col}`));
76
76
  }
77
- const alias = joinAlias ?? qb.alias;
77
+ const alias = joinAlias ?? ownerAlias ?? 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
  }
@@ -76,7 +76,7 @@ class ObjectCriteriaNode extends CriteriaNode_1.CriteriaNode {
76
76
  this.inlineChildPayload(o, payload, field, a, childAlias);
77
77
  }
78
78
  else if (childNode.shouldRename(payload)) {
79
- this.inlineCondition(childNode.renameFieldToPK(qb), o, payload);
79
+ this.inlineCondition(childNode.renameFieldToPK(qb, alias), o, payload);
80
80
  }
81
81
  else if (isRawField) {
82
82
  const rawField = core_1.RawQueryFragment.getKnownFragment(field);
@@ -315,6 +315,10 @@ class QueryBuilderHelper {
315
315
  if (prop?.customType) {
316
316
  value = prop.customType.convertToDatabaseValue(value, this.platform, { fromQuery: true, key, mode: 'query' });
317
317
  }
318
+ if (Array.isArray(value) && key.includes(core_1.Utils.PK_SEPARATOR)) {
319
+ const val = `(${value.map(() => '?').join(', ')})`;
320
+ value = this.knex.raw(val, value);
321
+ }
318
322
  params.push(value);
319
323
  }
320
324
  return `${this.knex.ref(column)} ${replacement} ${value === null ? 'null' : '?'}`;
package/typings.d.ts CHANGED
@@ -186,7 +186,7 @@ export interface ICriteriaNode<T extends object> {
186
186
  shouldInline(payload: any): boolean;
187
187
  willAutoJoin(qb: IQueryBuilder<T>, alias?: string, options?: ICriteriaNodeProcessOptions): boolean;
188
188
  shouldRename(payload: any): boolean;
189
- renameFieldToPK<T>(qb: IQueryBuilder<T>): string;
189
+ renameFieldToPK<T>(qb: IQueryBuilder<T>, ownerAlias?: string): string;
190
190
  getPath(addIndex?: boolean): string;
191
191
  getPivotPath(path: string): string;
192
192
  }