Skip to content

Commit 4763690

Browse files
committed
fix(sql-orm-client): namespace-aware through resolver after TML-2605 rebase
Main's namespace work (TML-2605) removed the unboundTable helper the resolver relied on and made runtime SQL namespace-qualified. Resolve the junction via resolveTableForContract so requiredPayloadColumns reads the correct table and the resolved namespaceId is carried on the descriptor. Consolidate ResolvedThrough onto ContractRelationThrough (export the latter from @prisma-next/contract) and surface the junction namespaceId, addressing Will's review on #678 (collection-contract.ts:201 'Needs namespace' + 'Duplicate of ContractRelationThrough?'). Signed-off-by: Alexey Orlenko's AI Agent <robot@aqrln.net>
1 parent db64368 commit 4763690

3 files changed

Lines changed: 10 additions & 8 deletions

File tree

packages/1-framework/0-foundation/contract/src/exports/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export type {
3030
ContractReferenceRelation,
3131
ContractRelation,
3232
ContractRelationOn,
33+
ContractRelationThrough,
3334
ContractValueObject,
3435
ContractVariantEntry,
3536
EmbedRelationKeys,

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
type Contract,
33
type ContractFieldType,
4+
type ContractRelationThrough,
45
type CrossReference,
56
domainModelsAtDefaultNamespace,
67
} from '@prisma-next/contract/types';
@@ -198,11 +199,9 @@ export function getCompleteColumnToFieldMap(
198199
return cached;
199200
}
200201

201-
interface ResolvedThrough {
202-
readonly table: string;
203-
readonly parentColumns: readonly string[];
204-
readonly childColumns: readonly string[];
205-
readonly targetColumns: readonly string[];
202+
interface ResolvedThrough extends ContractRelationThrough {
203+
/** Namespace of the junction table, resolved from storage. */
204+
readonly namespaceId?: string;
206205
readonly requiredPayloadColumns: readonly string[];
207206
}
208207

@@ -276,10 +275,10 @@ function resolveThrough(
276275
...castAs<readonly string[]>(parentColumns),
277276
...castAs<readonly string[]>(childColumns),
278277
]);
279-
const junctionTable = unboundTable(contract, table);
278+
const resolvedJunction = resolveTableForContract(contract, table);
280279
const requiredPayloadColumns: string[] = [];
281-
if (junctionTable) {
282-
for (const [colName, col] of Object.entries(junctionTable.columns)) {
280+
if (resolvedJunction) {
281+
for (const [colName, col] of Object.entries(resolvedJunction.table.columns)) {
283282
if (!fkColumnSet.has(colName) && !col.nullable && col.default === undefined) {
284283
requiredPayloadColumns.push(colName);
285284
}
@@ -292,6 +291,7 @@ function resolveThrough(
292291
childColumns: castAs<readonly string[]>(childColumns),
293292
targetColumns: castAs<readonly string[]>(targetColumns),
294293
requiredPayloadColumns,
294+
...(resolvedJunction !== undefined ? { namespaceId: resolvedJunction.namespaceId } : {}),
295295
};
296296
}
297297

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,7 @@ describe('resolveModelRelations() through descriptor', () => {
476476
childColumns: ['child_id'],
477477
targetColumns: ['id'],
478478
requiredPayloadColumns: [],
479+
namespaceId: 'public',
479480
});
480481
});
481482

0 commit comments

Comments
 (0)