orchid-orm 1.24.2 → 1.24.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
@@ -226,12 +226,8 @@ const joinQueryChainingHOF = (reverseJoin, joinQuery) => (joiningQuery, baseQuer
226
226
  }
227
227
  const last = chain[chain.length - 1];
228
228
  const query = "relationConfig" in last ? last.relationConfig.joinQuery(last, baseQuery) : last;
229
- const inner = reverseJoin(query, joiningQuery);
230
229
  return joiningQuery.where({
231
- EXISTS: {
232
- first: inner,
233
- args: orchidCore.emptyArray
234
- }
230
+ EXISTS: { q: reverseJoin(query, joiningQuery) }
235
231
  });
236
232
  };
237
233
 
@@ -1191,19 +1187,23 @@ const makeHasAndBelongsToManyMethod = (table, qb, relation, relationName, query)
1191
1187
  throughForeignKeysFull,
1192
1188
  throughPrimaryKeysFull
1193
1189
  };
1194
- const joinQuery = (joiningQuery, tableAs, foreignAs) => {
1195
- return joiningQuery.whereExists(subQuery, (q) => {
1196
- for (let i = 0; i < throughLen; i++) {
1197
- pqb._queryJoinOn(q, [
1198
- throughForeignKeysFull[i],
1199
- `${foreignAs}.${throughPrimaryKeys[i]}`
1200
- ]);
1201
- }
1202
- for (let i = 0; i < len; i++) {
1203
- pqb._queryJoinOn(q, [foreignKeysFull[i], `${tableAs}.${primaryKeys[i]}`]);
1190
+ const joinQuery = (joiningQuery, tableAs, foreignAs, joinedShapes) => {
1191
+ const cloned = joiningQuery.clone();
1192
+ cloned.q.joinedShapes = joinedShapes;
1193
+ return pqb._queryWhereExists(cloned, subQuery, [
1194
+ (q) => {
1195
+ for (let i = 0; i < throughLen; i++) {
1196
+ pqb._queryJoinOn(q, [
1197
+ throughForeignKeysFull[i],
1198
+ `${foreignAs}.${throughPrimaryKeys[i]}`
1199
+ ]);
1200
+ }
1201
+ for (let i = 0; i < len; i++) {
1202
+ pqb._queryJoinOn(q, [foreignKeysFull[i], `${tableAs}.${primaryKeys[i]}`]);
1203
+ }
1204
+ return q;
1204
1205
  }
1205
- return q;
1206
- });
1206
+ ]);
1207
1207
  };
1208
1208
  const obj = {};
1209
1209
  for (let i = 0; i < len; i++) {
@@ -1211,11 +1211,10 @@ const makeHasAndBelongsToManyMethod = (table, qb, relation, relationName, query)
1211
1211
  }
1212
1212
  const selectPrimaryKeysAsForeignKeys = [{ selectAs: obj }];
1213
1213
  const reverseJoin = (baseQuery2, joiningQuery) => {
1214
- return joinQuery(
1215
- baseQuery2,
1216
- pqb.getQueryAs(baseQuery2),
1217
- pqb.getQueryAs(joiningQuery)
1218
- );
1214
+ const foreignAs = pqb.getQueryAs(joiningQuery);
1215
+ return joinQuery(baseQuery2, pqb.getQueryAs(baseQuery2), foreignAs, __spreadProps$1(__spreadValues$3({}, baseQuery2.q.joinedShapes), {
1216
+ [foreignAs]: joiningQuery.q.shape
1217
+ }));
1219
1218
  };
1220
1219
  return {
1221
1220
  returns: "many",
@@ -1240,17 +1239,12 @@ const makeHasAndBelongsToManyMethod = (table, qb, relation, relationName, query)
1240
1239
  relationName,
1241
1240
  state
1242
1241
  ),
1243
- joinQuery: joinQueryChainingHOF(reverseJoin, (joiningQuery, baseQuery2) => {
1244
- const joined = joinQuery(
1245
- joiningQuery,
1246
- pqb.getQueryAs(baseQuery2),
1247
- pqb.getQueryAs(joiningQuery)
1248
- );
1249
- joined.q.joinedShapes = __spreadProps$1(__spreadValues$3({}, joined.q.joinedShapes), {
1242
+ joinQuery: joinQueryChainingHOF(
1243
+ reverseJoin,
1244
+ (joiningQuery, baseQuery2) => joinQuery(joiningQuery, pqb.getQueryAs(baseQuery2), pqb.getQueryAs(joiningQuery), __spreadProps$1(__spreadValues$3({}, joiningQuery.q.joinedShapes), {
1250
1245
  [baseQuery2.q.as || baseQuery2.table]: baseQuery2.q.shape
1251
- });
1252
- return joined;
1253
- }),
1246
+ }))
1247
+ ),
1254
1248
  reverseJoin,
1255
1249
  modifyRelatedQuery(relationQuery) {
1256
1250
  const ref = {};
@@ -1348,7 +1342,9 @@ const nestedInsert = ({
1348
1342
  for (const [, { connect }] of items) {
1349
1343
  for (const item of connect) {
1350
1344
  queries.push(
1351
- pqb._queryFindBy(t.select(...throughPrimaryKeys), [item])
1345
+ pqb._queryFindBy(t.select(...throughPrimaryKeys), [
1346
+ item
1347
+ ])
1352
1348
  );
1353
1349
  }
1354
1350
  }
@@ -1738,10 +1734,7 @@ const makeRelationQuery = (table, relationName, data, q) => {
1738
1734
  } else {
1739
1735
  query = pqb._queryWhere(pqb._queryAll(toTable), [
1740
1736
  {
1741
- EXISTS: {
1742
- first: data.reverseJoin(this, toTable),
1743
- args: orchidCore.emptyArray
1744
- }
1737
+ EXISTS: { q: data.reverseJoin(this, toTable) }
1745
1738
  }
1746
1739
  ]);
1747
1740
  }