Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions packages/runtime/src/enhancements/node/delegate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,9 @@ export class DelegateProxyHandler extends DefaultPrismaProxyHandler {
data[field] = {};
}
await this.injectSelectIncludeHierarchy(fieldInfo.type, data[field]);
if (data[field].where) {
this.injectWhereHierarchy(fieldInfo.type, data[field].where);
}
}
}

Expand Down
83 changes: 83 additions & 0 deletions tests/regression/tests/issue-2246.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { loadSchema } from '@zenstackhq/testtools';
import { title } from 'process';

describe('issue 2246', () => {
it('regression', async () => {
const { enhance } = await loadSchema(
`
model Media {
id Int @id @default(autoincrement())
title String
mediaType String

@@delegate(mediaType)
@@allow('all', true)
}

model Movie extends Media {
director Director @relation(fields: [directorId], references: [id])
directorId Int
duration Int
rating String
}

model Director {
id Int @id @default(autoincrement())
name String
email String
movies Movie[]

@@allow('all', true)
}
`
);

const db = enhance();

await db.director.create({
data: {
name: 'Christopher Nolan',
email: '[email protected]',
movies: {
create: {
title: 'Inception',
duration: 148,
rating: 'PG-13',
},
},
},
});

await expect(
db.director.findMany({
include: {
movies: {
where: { title: 'Inception' },
},
},
})
).resolves.toHaveLength(1);

await expect(
db.director.findFirst({
include: {
_count: { select: { movies: { where: { title: 'Inception' } } } },
},
})
).resolves.toMatchObject({ _count: { movies: 1 } });

await expect(
db.movie.findMany({
where: { title: 'Interstellar' },
})
).resolves.toHaveLength(0);

await expect(
db.director.findFirst({
include: {
_count: { select: { movies: { where: { title: 'Interstellar' } } } },
},
})
).resolves.toMatchObject({ _count: { movies: 0 } });
});
});
Loading