orchid-orm 1.23.11 → 1.24.1

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
@@ -1035,7 +1035,7 @@ const nestedUpdate$1 = ({ query, primaryKeys, foreignKeys }) => {
1035
1035
  ),
1036
1036
  obj
1037
1037
  );
1038
- if (params.set) {
1038
+ if (params.set && (Array.isArray(params.set) ? params.set.length : orchidCore.objectHasValues(params.set))) {
1039
1039
  delete t.q[pqb.toSQLCacheKey];
1040
1040
  const obj2 = {};
1041
1041
  for (let i = 0; i < len; i++) {
@@ -1144,10 +1144,17 @@ const makeHasAndBelongsToManyMethod = (table, qb, relation, relationName, query)
1144
1144
  throughForeignKeys = [options.associationForeignKey];
1145
1145
  throughPrimaryKeys = [options.associationPrimaryKey];
1146
1146
  }
1147
- const foreignKeysFull = foreignKeys.map((key) => `${joinTable}.${key}`);
1148
- const throughForeignKeysFull = throughForeignKeys.map(
1149
- (key) => `${joinTable}.${key}`
1150
- );
1147
+ const { snakeCase } = table.internal;
1148
+ const foreignKeysFull = foreignKeys.map((key, i) => {
1149
+ if (snakeCase)
1150
+ key = foreignKeys[i] = orchidCore.toSnakeCase(key);
1151
+ return `${joinTable}.${key}`;
1152
+ });
1153
+ const throughForeignKeysFull = throughForeignKeys.map((key, i) => {
1154
+ if (snakeCase)
1155
+ key = throughForeignKeys[i] = orchidCore.toSnakeCase(key);
1156
+ return `${joinTable}.${key}`;
1157
+ });
1151
1158
  const foreignTable = pqb.getQueryAs(query);
1152
1159
  const throughPrimaryKeysFull = throughPrimaryKeys.map(
1153
1160
  (key) => `${foreignTable}.${key}`
@@ -1533,15 +1540,17 @@ const nestedUpdate = (state) => {
1533
1540
  const j = queryJoinTable(state, data);
1534
1541
  await pqb._queryDelete(j);
1535
1542
  delete j.q[pqb.toSQLCacheKey];
1536
- const idsRows = await pqb._queryRows(
1537
- pqb._querySelect(
1538
- state.relatedTableQuery.where(
1539
- conditionsToWhereArg(params.set)
1540
- ),
1541
- state.throughPrimaryKeys
1542
- )
1543
- );
1544
- await insertToJoinTable(state, j, data, idsRows);
1543
+ if (Array.isArray(params.set) ? params.set.length : orchidCore.objectHasValues(params.set)) {
1544
+ const idsRows = await pqb._queryRows(
1545
+ pqb._querySelect(
1546
+ state.relatedTableQuery.where(
1547
+ conditionsToWhereArg(params.set)
1548
+ ),
1549
+ state.throughPrimaryKeys
1550
+ )
1551
+ );
1552
+ await insertToJoinTable(state, j, data, idsRows);
1553
+ }
1545
1554
  }
1546
1555
  };
1547
1556
  };
@@ -1858,7 +1867,8 @@ const orchidORM = (_a, tables) => {
1858
1867
  schema: table.schema,
1859
1868
  language: table.language,
1860
1869
  scopes: table.scopes,
1861
- softDelete: table.softDelete
1870
+ softDelete: table.softDelete,
1871
+ snakeCase: table.snakeCase
1862
1872
  });
1863
1873
  if (table.noPrimaryKey)
1864
1874
  options2.noPrimaryKey = "ignore";