orchid-orm 1.49.2 → 1.49.3

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.js CHANGED
@@ -234,7 +234,7 @@ function joinHasRelation(baseQuery, joiningQuery, primaryKeys, foreignKeys, len)
234
234
  }
235
235
  return q;
236
236
  }
237
- const addAutoForeignKey = (tableConfig, from, to, primaryKeys, foreignKeys, options) => {
237
+ const addAutoForeignKey = (tableConfig, from, to, primaryKeys, foreignKeys, options, originalForeignKeys) => {
238
238
  var _a;
239
239
  const toTable = to.table;
240
240
  let fkeyOptions = options.foreignKey !== void 0 ? options.foreignKey : tableConfig.autoForeignKeys;
@@ -273,7 +273,7 @@ const addAutoForeignKey = (tableConfig, from, to, primaryKeys, foreignKeys, opti
273
273
  }
274
274
  ((_a = from.internal.tableData).constraints ?? (_a.constraints = [])).push({
275
275
  references: {
276
- columns: foreignKeys,
276
+ columns: originalForeignKeys || foreignKeys,
277
277
  fnOrTable: toTable,
278
278
  foreignColumns: primaryKeys,
279
279
  options: fkeyOptions
@@ -307,6 +307,7 @@ const joinQueryChainHOF = (relPKeys, reverseJoin, joinQuery) => (joiningQuery, b
307
307
  }
308
308
  const item = selectRowNumber(result, relPKeys);
309
309
  combineOrdering(result, query);
310
+ if (!result.q.select) result.q.select = ["*"];
310
311
  return wrapQuery(jq, result, item);
311
312
  };
312
313
  const selectRowNumber = (result, relPKeys) => {
@@ -1317,17 +1318,19 @@ const removeColumnName = (column) => {
1317
1318
  };
1318
1319
  const makeHasAndBelongsToManyMethod = (tableConfig, table, qb, relation, relationName, query) => {
1319
1320
  const { options } = relation;
1321
+ const { snakeCase } = table.internal;
1320
1322
  const primaryKeys = options.columns;
1321
1323
  const foreignKeys = options.references;
1324
+ const originalForeignKeys = snakeCase ? [...foreignKeys] : foreignKeys;
1322
1325
  const joinTable = options.through.table;
1323
1326
  const throughForeignKeys = options.through.columns;
1327
+ const originalThroughForeignKeys = snakeCase ? [...throughForeignKeys] : throughForeignKeys;
1324
1328
  const throughPrimaryKeys = options.through.references;
1325
1329
  const { on } = options;
1326
1330
  if (on) {
1327
1331
  pqb._queryWhere(query, [on]);
1328
1332
  pqb._queryDefaults(query, on);
1329
1333
  }
1330
- const { snakeCase } = table.internal;
1331
1334
  const foreignKeysFull = foreignKeys.map((key, i) => {
1332
1335
  if (snakeCase) key = foreignKeys[i] = orchidCore.toSnakeCase(key);
1333
1336
  return `${joinTable}.${key}`;
@@ -1369,7 +1372,8 @@ const makeHasAndBelongsToManyMethod = (tableConfig, table, qb, relation, relatio
1369
1372
  table,
1370
1373
  primaryKeys,
1371
1374
  foreignKeys,
1372
- relation.options
1375
+ relation.options,
1376
+ originalForeignKeys
1373
1377
  );
1374
1378
  addAutoForeignKey(
1375
1379
  tableConfig,
@@ -1377,7 +1381,8 @@ const makeHasAndBelongsToManyMethod = (tableConfig, table, qb, relation, relatio
1377
1381
  query,
1378
1382
  throughPrimaryKeys,
1379
1383
  throughForeignKeys,
1380
- relation.options.through
1384
+ relation.options.through,
1385
+ originalThroughForeignKeys
1381
1386
  );
1382
1387
  const state = {
1383
1388
  relatedTableQuery: query,
@@ -2080,7 +2085,7 @@ const orchidORM = ({
2080
2085
  table.types,
2081
2086
  transactionStorage,
2082
2087
  options2,
2083
- table.constructor.prototype.tableData ?? orchidCore.emptyObject
2088
+ table.constructor.prototype.tableData ?? {}
2084
2089
  );
2085
2090
  dbTable.definedAs = key;
2086
2091
  dbTable.db = result;