Skip to content

Commit a90435d

Browse files
committed
fix: relation fields are included even if they are set false in select clause
1 parent cb50826 commit a90435d

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

packages/runtime/src/enhancements/policy/policy-utils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,10 @@ export class PolicyUtil extends QueryUtils {
653653
const hoistedConditions: any[] = [];
654654

655655
for (const field of getModelFields(injectTarget)) {
656+
if (injectTarget[field] === false) {
657+
continue;
658+
}
659+
656660
const fieldInfo = resolveField(this.modelMeta, model, field);
657661
if (!fieldInfo || !fieldInfo.isDataModel) {
658662
// only care about relation fields

packages/schema/src/language-server/validator/expression-validator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export default class ExpressionValidator implements AstValidator<Expression> {
3030
// check was done at link time
3131
accept(
3232
'error',
33-
'auth() cannot be resolved because no model marked wth "@@auth()" or named "User" is found',
33+
'auth() cannot be resolved because no model marked with "@@auth()" or named "User" is found',
3434
{ node: expr }
3535
);
3636
} else {
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { loadSchema } from '@zenstackhq/testtools';
2+
3+
describe('issue 1427', () => {
4+
it('regression', async () => {
5+
const { prisma, enhance } = await loadSchema(
6+
`
7+
model User {
8+
id String @id @default(cuid())
9+
name String
10+
profile Profile?
11+
@@allow('all', true)
12+
}
13+
14+
model Profile {
15+
id String @id @default(cuid())
16+
user User @relation(fields: [userId], references: [id])
17+
userId String @unique
18+
@@allow('all', true)
19+
}
20+
`
21+
);
22+
23+
await prisma.user.create({
24+
data: {
25+
name: 'John',
26+
profile: {
27+
create: {},
28+
},
29+
},
30+
});
31+
32+
const db = enhance();
33+
const found = await db.user.findFirst({
34+
select: {
35+
id: true,
36+
name: true,
37+
profile: false,
38+
},
39+
});
40+
expect(found.profile).toBeUndefined();
41+
});
42+
});

0 commit comments

Comments
 (0)