Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/orm/src/client/executor/name-mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,10 @@ export class QueryNameMapper extends OperationNodeTransformer {

private processEnumSelection(selection: SelectionNodeChild, fieldName: string) {
const { alias, node } = stripAlias(selection);
const fieldScope = this.resolveFieldFromScopes(fieldName);
const fieldScope = this.resolveFieldFromScopes(
fieldName,
ReferenceNode.is(node) ? node.table?.table?.identifier.name : undefined,
);
if (!fieldScope || !fieldScope.model) {
return selection;
}
Expand Down
40 changes: 40 additions & 0 deletions tests/regression/test/issue-2825.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { createTestClient } from '@zenstackhq/testtools';
import { describe, it } from 'vitest';

// https://github.com/zenstackhq/zenstack/issues/2825
describe('Regression for issue #2825', () => {
it('handle same column name with enum type', async () => {
const schema = `
enum UserStatus {
OK1 @map("ok1")
NO1 @map("no1")

@@map("user_status")
}

enum PostStatus {
OK2 @map("ok2")
NO2 @map("no2")

@@map("post_status")
}

model User {
id Int @id @default(autoincrement())
status UserStatus?
posts Post[]
}

model Post {
id Int @id @default(autoincrement())
status PostStatus?
author User? @relation(fields: [authorId], references: [id])
authorId Int
}
`;

const db = await createTestClient(schema, { usePrismaPush: true, provider: 'postgresql' });

await db.$qb.selectFrom('User as u').innerJoin('Post as p', 'p.authorId', 'u.id').select('u.status').execute();
Comment thread
ymc9 marked this conversation as resolved.
});
});
Loading