orchid-orm 1.9.11 → 1.9.12

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
@@ -1206,7 +1206,9 @@ const delayRelation = (delayedRelations, table, relationName, data) => {
1206
1206
  };
1207
1207
  const applyRelation = (qb, { relationName, relation, dbTable, otherDbTable }, delayedRelations) => {
1208
1208
  var _a;
1209
- const query = (relation.options.scope ? relation.options.scope(otherDbTable) : otherDbTable).as(relationName);
1209
+ const baseQuery = Object.create(otherDbTable);
1210
+ baseQuery.baseQuery = baseQuery;
1211
+ const query = (relation.options.scope ? relation.options.scope(baseQuery) : baseQuery).as(relationName);
1210
1212
  const definedAs = query.definedAs;
1211
1213
  if (!definedAs) {
1212
1214
  throw new Error(
@@ -1239,6 +1241,7 @@ const applyRelation = (qb, { relationName, relation, dbTable, otherDbTable }, de
1239
1241
  dbTable.shape[relationName] = dbTable.query.shape[relationName] = data.virtualColumn;
1240
1242
  }
1241
1243
  makeRelationQuery(dbTable, definedAs, relationName, data);
1244
+ baseQuery.joinQuery = data.joinQuery;
1242
1245
  dbTable.relations[relationName] = {
1243
1246
  type,
1244
1247
  key: relationName,
@@ -1248,6 +1251,7 @@ const applyRelation = (qb, { relationName, relation, dbTable, otherDbTable }, de
1248
1251
  primaryKey: data.primaryKey,
1249
1252
  options: relation.options
1250
1253
  };
1254
+ dbTable.relationsQueries[relationName] = query;
1251
1255
  const tableRelations = delayedRelations.get(dbTable);
1252
1256
  if (!tableRelations)
1253
1257
  return;