orchid-orm 1.9.15 → 1.9.17

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.mjs CHANGED
@@ -1236,11 +1236,12 @@ const applyRelation = (qb, { relationName, relation, dbTable, otherDbTable }, de
1236
1236
  }
1237
1237
  if (data.returns === "one") {
1238
1238
  query._take();
1239
+ query.query.returnsOne = true;
1239
1240
  }
1240
1241
  if (data.virtualColumn) {
1241
1242
  dbTable.shape[relationName] = dbTable.query.shape[relationName] = data.virtualColumn;
1242
1243
  }
1243
- makeRelationQuery(dbTable, definedAs, relationName, data);
1244
+ makeRelationQuery(dbTable, relationName, data, query);
1244
1245
  baseQuery.joinQuery = data.joinQuery;
1245
1246
  dbTable.relations[relationName] = {
1246
1247
  type,
@@ -1259,17 +1260,14 @@ const applyRelation = (qb, { relationName, relation, dbTable, otherDbTable }, de
1259
1260
  applyRelation(qb, data2, delayedRelations);
1260
1261
  });
1261
1262
  };
1262
- const makeRelationQuery = (table, definedAs, relationName, data) => {
1263
+ const makeRelationQuery = (table, relationName, data, q) => {
1263
1264
  Object.defineProperty(table, relationName, {
1264
1265
  get() {
1265
1266
  var _a;
1266
- const toTable = this.db[definedAs].as(relationName);
1267
- if (data.returns === "one") {
1268
- toTable._take();
1269
- }
1267
+ const toTable = q.clone();
1270
1268
  const query = this.isSubQuery ? toTable : toTable._whereExists(
1271
1269
  this.baseQuery,
1272
- (q) => data.reverseJoin(this, toTable)
1270
+ (q2) => data.reverseJoin(this, toTable)
1273
1271
  );
1274
1272
  query.query[relationQueryKey] = {
1275
1273
  relationName,