orchid-orm 1.9.15 → 1.9.16

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
@@ -1255,11 +1255,12 @@ const applyRelation = (qb, { relationName, relation, dbTable, otherDbTable }, de
1255
1255
  }
1256
1256
  if (data.returns === "one") {
1257
1257
  query._take();
1258
+ query.query.returnsOne = true;
1258
1259
  }
1259
1260
  if (data.virtualColumn) {
1260
1261
  dbTable.shape[relationName] = dbTable.query.shape[relationName] = data.virtualColumn;
1261
1262
  }
1262
- makeRelationQuery(dbTable, definedAs, relationName, data);
1263
+ makeRelationQuery(dbTable, relationName, data, query);
1263
1264
  baseQuery.joinQuery = data.joinQuery;
1264
1265
  dbTable.relations[relationName] = {
1265
1266
  type,
@@ -1278,17 +1279,14 @@ const applyRelation = (qb, { relationName, relation, dbTable, otherDbTable }, de
1278
1279
  applyRelation(qb, data2, delayedRelations);
1279
1280
  });
1280
1281
  };
1281
- const makeRelationQuery = (table, definedAs, relationName, data) => {
1282
+ const makeRelationQuery = (table, relationName, data, q) => {
1282
1283
  Object.defineProperty(table, relationName, {
1283
1284
  get() {
1284
1285
  var _a;
1285
- const toTable = this.db[definedAs].as(relationName);
1286
- if (data.returns === "one") {
1287
- toTable._take();
1288
- }
1286
+ const toTable = q.clone();
1289
1287
  const query = this.isSubQuery ? toTable : toTable._whereExists(
1290
1288
  this.baseQuery,
1291
- (q) => data.reverseJoin(this, toTable)
1289
+ (q2) => data.reverseJoin(this, toTable)
1292
1290
  );
1293
1291
  query.query[pqb.relationQueryKey] = {
1294
1292
  relationName,