Skip to content

Commit 2a48241

Browse files
committed
feat(sql-orm-client): require junction namespaceId on the include through descriptor
The contract now carries the junction's namespaceId on through (slice 0); the include descriptor passes it through as a required field instead of re-deriving it from storage. Re-emit the M:N fixture so the User<->Tag through block carries it. Signed-off-by: Alexey Orlenko's AI Agent <robot@aqrln.net>
1 parent d339311 commit 2a48241

3 files changed

Lines changed: 5 additions & 5 deletions

File tree

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,13 +250,11 @@ export function resolveIncludeRelation(
250250
);
251251
through = {
252252
table: relation.through.table,
253+
namespaceId: relation.through.namespaceId,
253254
parentColumns: relation.through.parentColumns,
254255
childColumns: relation.through.childColumns,
255256
targetColumns: relation.through.targetColumns,
256257
parentLocalColumns,
257-
...(relation.through.namespaceId !== undefined
258-
? { namespaceId: relation.through.namespaceId }
259-
: {}),
260258
};
261259
}
262260

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ export interface IncludeCombine<ResultShape extends Record<string, unknown>>
5252

5353
export interface IncludeThroughDescriptor {
5454
readonly table: string;
55+
/** Namespace the junction table lives in, as declared in the contract. */
56+
readonly namespaceId: string;
5557
/** FK columns in the junction table that point to the parent. */
5658
readonly parentColumns: readonly string[];
5759
/** FK columns in the junction table that point to the target (child). */
@@ -60,8 +62,6 @@ export interface IncludeThroughDescriptor {
6062
readonly targetColumns: readonly string[];
6163
/** Resolved column names in the parent table that junction.parentColumns reference. */
6264
readonly parentLocalColumns: readonly string[];
63-
/** Namespace of the junction table, resolved from storage. */
64-
readonly namespaceId?: string;
6565
}
6666

6767
export interface IncludeExpr {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,7 @@ describe('M:N include correlated subquery', () => {
638638
cardinality: 'N:M',
639639
through: {
640640
table: opts.junctionTable,
641+
namespaceId: 'public',
641642
parentColumns: opts.parentColumns,
642643
childColumns: opts.childColumns,
643644
targetColumns: opts.targetColumns,
@@ -912,6 +913,7 @@ describe('M:N include correlated subquery', () => {
912913
cardinality: 'N:M',
913914
through: {
914915
table: 'parent_child',
916+
namespaceId: 'public',
915917
parentColumns: ['parent_id'],
916918
childColumns: ['child_id'],
917919
targetColumns: ['id'],

0 commit comments

Comments
 (0)