Skip to content

Commit ed06084

Browse files
committed
fix(sql-orm-client): namespace-qualify M:N include junction after TML-2605 rebase
Carry the resolved junction namespaceId onto IncludeThroughDescriptor and build the correlated include's junction TableSource with it, so the read path emits namespace-qualified SQL for the junction like the rest of the runtime after TML-2605. Signed-off-by: Alexey Orlenko's AI Agent <robot@aqrln.net>
1 parent f78fcc6 commit ed06084

3 files changed

Lines changed: 11 additions & 1 deletion

File tree

packages/3-extensions/sql-orm-client/src/collection-contract.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,9 @@ export function resolveIncludeRelation(
257257
childColumns: relation.through.childColumns,
258258
targetColumns: relation.through.targetColumns,
259259
parentLocalColumns,
260+
...(relation.through.namespaceId !== undefined
261+
? { namespaceId: relation.through.namespaceId }
262+
: {}),
260263
};
261264
}
262265

packages/3-extensions/sql-orm-client/src/query-plan-select.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ function buildManyToManyJunctionArtifacts(
313313
childColumns,
314314
targetColumns,
315315
parentLocalColumns,
316+
namespaceId,
316317
} = through;
317318

318319
const joinOnPairs = childColumns.map((junctionCol, i) =>
@@ -335,7 +336,11 @@ function buildManyToManyJunctionArtifacts(
335336
? castAs<AnyExpression>(correlationPairs[0]!)
336337
: AndExpr.of(correlationPairs);
337338

338-
const junctionJoin = JoinAst.inner(TableSource.named(junctionTable), joinOn, false);
339+
const junctionJoin = JoinAst.inner(
340+
TableSource.named(junctionTable, undefined, namespaceId),
341+
joinOn,
342+
false,
343+
);
339344

340345
return { whereExpr, junctionJoin };
341346
}

packages/3-extensions/sql-orm-client/src/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ export interface IncludeThroughDescriptor {
6060
readonly targetColumns: readonly string[];
6161
/** Resolved column names in the parent table that junction.parentColumns reference. */
6262
readonly parentLocalColumns: readonly string[];
63+
/** Namespace of the junction table, resolved from storage. */
64+
readonly namespaceId?: string;
6365
}
6466

6567
export interface IncludeExpr {

0 commit comments

Comments
 (0)