Skip to content

Commit f6d81d2

Browse files
committed
fix(orm): provide qualifier for enum resolveFieldFromScopes (#2825)
1 parent 0ad1dfb commit f6d81d2

2 files changed

Lines changed: 44 additions & 1 deletion

File tree

packages/orm/src/client/executor/name-mapper.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,10 @@ export class QueryNameMapper extends OperationNodeTransformer {
817817

818818
private processEnumSelection(selection: SelectionNodeChild, fieldName: string) {
819819
const { alias, node } = stripAlias(selection);
820-
const fieldScope = this.resolveFieldFromScopes(fieldName);
820+
const fieldScope = this.resolveFieldFromScopes(
821+
fieldName,
822+
ReferenceNode.is(node) ? node.table?.table?.identifier.name : undefined,
823+
);
821824
if (!fieldScope || !fieldScope.model) {
822825
return selection;
823826
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { createTestClient } from '@zenstackhq/testtools';
2+
import { describe, it } from 'vitest';
3+
4+
// https://github.com/zenstackhq/zenstack/issues/2825
5+
describe('Regression for issue #2825', () => {
6+
it('handle same column name with enum type', async () => {
7+
const schema = `
8+
enum UserStatus {
9+
OK1 @map("ok1")
10+
NO1 @map("no1")
11+
12+
@@map("user_status")
13+
}
14+
15+
enum PostStatus {
16+
OK2 @map("ok2")
17+
NO2 @map("no2")
18+
19+
@@map("post_status")
20+
}
21+
22+
model User {
23+
id Int @id @default(autoincrement())
24+
status UserStatus?
25+
posts Post[]
26+
}
27+
28+
model Post {
29+
id Int @id @default(autoincrement())
30+
status PostStatus?
31+
author User? @relation(fields: [authorId], references: [id])
32+
authorId Int
33+
}
34+
`;
35+
36+
const db = await createTestClient(schema, { usePrismaPush: true, provider: 'postgresql' });
37+
38+
await db.$qb.selectFrom('User as u').innerJoin('Post as p', 'p.authorId', 'u.id').select('u.status').execute();
39+
});
40+
});

0 commit comments

Comments
 (0)