@zenstackhq/orm 3.0.0-beta.31 → 3.0.0-beta.33

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/dist/index.cjs CHANGED
@@ -432,15 +432,16 @@ function getManyToManyRelation(schema, model, field) {
432
432
  if (!fieldDef.array || !fieldDef.relation?.opposite) {
433
433
  return void 0;
434
434
  }
435
+ const realModel = fieldDef.originModel ?? model;
435
436
  const oppositeFieldDef = requireField(schema, fieldDef.type, fieldDef.relation.opposite);
436
437
  if (oppositeFieldDef.array) {
437
438
  const sortedModelNames = [
438
- model,
439
+ realModel,
439
440
  fieldDef.type
440
441
  ].sort();
441
442
  let orderedFK;
442
- if (model !== fieldDef.type) {
443
- orderedFK = sortedModelNames[0] === model ? [
443
+ if (realModel !== fieldDef.type) {
444
+ orderedFK = sortedModelNames[0] === realModel ? [
444
445
  "A",
445
446
  "B"
446
447
  ] : [
@@ -460,7 +461,7 @@ function getManyToManyRelation(schema, model, field) {
460
461
  "A"
461
462
  ];
462
463
  }
463
- const modelIdFields = requireIdFields(schema, model);
464
+ const modelIdFields = requireIdFields(schema, realModel);
464
465
  (0, import_common_helpers.invariant)(modelIdFields.length === 1, "Only single-field ID is supported for many-to-many relation");
465
466
  const otherIdFields = requireIdFields(schema, fieldDef.type);
466
467
  (0, import_common_helpers.invariant)(otherIdFields.length === 1, "Only single-field ID is supported for many-to-many relation");
@@ -6360,7 +6361,7 @@ var ZenStackQueryExecutor = class _ZenStackQueryExecutor extends import_kysely7.
6360
6361
  parameters
6361
6362
  };
6362
6363
  }
6363
- return connection.executeQuery(compiled);
6364
+ return this.internalExecuteQuery(connection, compiled);
6364
6365
  }
6365
6366
  if ((import_kysely7.InsertQueryNode.is(query) || import_kysely7.UpdateQueryNode.is(query)) && this.hasEntityMutationPluginsWithAfterMutationHooks) {
6366
6367
  query = {
@@ -6389,7 +6390,7 @@ var ZenStackQueryExecutor = class _ZenStackQueryExecutor extends import_kysely7.
6389
6390
  return beforeMutationEntities;
6390
6391
  }, "loadBeforeMutationEntities");
6391
6392
  await this.callBeforeMutationHooks(finalQuery, mutationInfo, loadBeforeMutationEntities, connectionClient, queryId);
6392
- const result = await connection.executeQuery(compiled);
6393
+ const result = await this.internalExecuteQuery(connection, compiled);
6393
6394
  if (!this.driver.isTransactionConnection(connection)) {
6394
6395
  await this.callAfterMutationHooks(result, finalQuery, mutationInfo, connectionClient, "all", queryId);
6395
6396
  } else {
@@ -6526,7 +6527,7 @@ var ZenStackQueryExecutor = class _ZenStackQueryExecutor extends import_kysely7.
6526
6527
  where: this.andNodes(selectQueryNode.where, where)
6527
6528
  };
6528
6529
  const compiled = this.compileQuery(selectQueryNode, (0, import_kysely7.createQueryId)());
6529
- const result = await connection.executeQuery(compiled);
6530
+ const result = await this.internalExecuteQuery(connection, compiled);
6530
6531
  return result.rows;
6531
6532
  }
6532
6533
  andNodes(condition1, condition2) {
@@ -6538,6 +6539,13 @@ var ZenStackQueryExecutor = class _ZenStackQueryExecutor extends import_kysely7.
6538
6539
  return condition2;
6539
6540
  }
6540
6541
  }
6542
+ async internalExecuteQuery(connection, compiledQuery) {
6543
+ try {
6544
+ return await connection.executeQuery(compiledQuery);
6545
+ } catch (err) {
6546
+ throw createDBQueryError("Failed to execute query", err, compiledQuery.sql, compiledQuery.parameters);
6547
+ }
6548
+ }
6541
6549
  };
6542
6550
 
6543
6551
  // src/client/functions.ts