@mikro-orm/sql 7.2.8-dev.6 → 7.2.8-dev.8

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/sql",
3
- "version": "7.2.8-dev.6",
3
+ "version": "7.2.8-dev.8",
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",
@@ -53,7 +53,7 @@
53
53
  "@mikro-orm/core": "^7.2.7"
54
54
  },
55
55
  "peerDependencies": {
56
- "@mikro-orm/core": "7.2.8-dev.6"
56
+ "@mikro-orm/core": "7.2.8-dev.8"
57
57
  },
58
58
  "engines": {
59
59
  "node": ">= 22.17.0"
@@ -593,6 +593,16 @@ export class QueryBuilder {
593
593
  o[raw('??', [key])] = o[key];
594
594
  delete o[key];
595
595
  }
596
+ // an alias-prefixed composite FK needs all its columns, like the unprefixed form gets in `renameFieldToPK()`
597
+ const [alias, field] = key.includes('.') ? this.helper.splitField(key, true) : [];
598
+ const prop = field && !Utils.isPlainObject(o[key]) ? this.helper.getProperty(field, alias) : undefined;
599
+ if (prop &&
600
+ prop.joinColumns?.length > 1 &&
601
+ (prop.kind === ReferenceKind.MANY_TO_ONE || (prop.kind === ReferenceKind.ONE_TO_ONE && prop.owner))) {
602
+ const columns = prop.polymorphic ? prop.fieldNames : prop.joinColumns;
603
+ o[Utils.getPrimaryKeyHash(columns.map(col => `${alias}.${col}`))] = o[key];
604
+ delete o[key];
605
+ }
596
606
  }
597
607
  this.helper.validateQueryOrder(o);
598
608
  const processed = QueryHelper.processWhere({
@@ -2354,8 +2364,12 @@ export class QueryBuilder {
2354
2364
  if (this.#state.orderBy.length > 0) {
2355
2365
  const orderBy = [];
2356
2366
  for (const orderMap of this.#state.orderBy) {
2357
- for (const field of Utils.getObjectQueryKeys(orderMap)) {
2358
- const direction = orderMap[field];
2367
+ // a composite FK key holds several columns, each needs its own `min()`
2368
+ const entries = Utils.getObjectQueryKeys(orderMap).flatMap(key => {
2369
+ const fields = RawQueryFragment.isKnownFragmentSymbol(key) ? [key] : Utils.splitPrimaryKeys(key);
2370
+ return fields.map(field => [field, orderMap[key]]);
2371
+ });
2372
+ for (const [field, direction] of entries) {
2359
2373
  if (RawQueryFragment.isKnownFragmentSymbol(field)) {
2360
2374
  orderBy.push({ [field]: direction });
2361
2375
  continue;
@@ -557,15 +557,17 @@ export class QueryBuilderHelper {
557
557
  ['$in', '$nin'].includes(op) &&
558
558
  Array.isArray(value[op]) &&
559
559
  value[op].every((v) => Array.isArray(v));
560
- if (fields.length > 1 && Array.isArray(value[op])) {
560
+ // an empty list falls through to the generic `1 = 0` / `1 = 1` handling below
561
+ if (fields.length > 1 && Array.isArray(value[op]) && value[op].length > 0) {
561
562
  const singleTuple = !value[op].every((v) => Array.isArray(v));
562
563
  if (!this.#platform.allowsComparingTuples()) {
563
564
  const mapped = fields.map(f => this.mapper(f, type));
564
- if (op === '$in') {
565
+ if (op === '$in' || op === '$nin') {
565
566
  const conds = value[op].map(() => {
566
567
  return `(${mapped.map(field => `${this.#platform.quoteIdentifier(field)} = ?`).join(' and ')})`;
567
568
  });
568
- parts.push(`(${conds.join(' or ')})`);
569
+ const sql = `(${conds.join(' or ')})`;
570
+ parts.push(op === '$in' ? sql : `not ${sql}`);
569
571
  params.push(...Utils.flatten(value[op]));
570
572
  return { sql: parts.join(' and '), params };
571
573
  }
@@ -1203,6 +1203,8 @@ export class DatabaseTable {
1203
1203
  // collapse mysql's `""` for unset comments to `null` so both sources agree. drop entirely on
1204
1204
  // platforms that can't read comments back (sqlite), where keeping it would flip the snapshot
1205
1205
  comment: supportsComments ? this.comment || null : null,
1206
+ // JSON.stringify drops it when unset, so snapshots of unpartitioned tables stay unchanged
1207
+ partitioning: this.partitioning,
1206
1208
  };
1207
1209
  // emit RLS state only when set, so snapshots of non-RLS tables stay byte-for-byte unchanged
1208
1210
  if (sortedPolicies.length > 0) {