Skip to content

Commit

Permalink
Merge pull request #1100 from morintd/fix_query_null
Browse files Browse the repository at this point in the history
fix: 🐛 properly query with child: null
  • Loading branch information
morintd authored Sep 21, 2024
2 parents ee14fb2 + 2e7e30d commit 8187e2d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
13 changes: 13 additions & 0 deletions src/__tests__/find/find.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,19 @@ describe('find', () => {

expect(realBlogs).toEqual(mockBlogs);
});

it(`Should match on null`, async () => {
const realBlogs = await prisma.blog.findMany({
where: { author: null },
select: { title: true },
});
const mockBlogs = await prismock.blog.findMany({
where: { author: null },
select: { title: true },
});

expect(realBlogs).toEqual(mockBlogs);
});
});

it('should correctly query on Datetime type field', async () => {
Expand Down
12 changes: 10 additions & 2 deletions src/lib/operations/find/match.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,19 @@ export const matchMultiple = (item: Item, where: FindWhereArgs, current: Delegat
return false;
}

if (filter == null || filter === undefined) {
if (filter === null) return val === null || val === undefined;
if (filter === undefined) {
return true;
}

if (filter === null) {
const field = current.model.fields.find((field) => field.name === child);

if (field?.relationFromFields && field.relationFromFields.length > 0) {
return item[field.relationFromFields[0]] === null || item[field.relationFromFields[0]] === undefined;
}
return val === null || val === undefined;
}

// Support querying fields with bigint in query.
if (typeof filter === 'bigint') {
if (filter === BigInt(val)) {
Expand Down

0 comments on commit 8187e2d

Please sign in to comment.