-
-
Notifications
You must be signed in to change notification settings - Fork 113
fix(polymorphism): support orderBy
with base fields
#1086
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -235,6 +235,41 @@ describe('Polymorphism Test', () => { | |
expect(imgAsset.owner).toMatchObject(user); | ||
}); | ||
|
||
it('order by base fields', async () => { | ||
const { db, user } = await setup(); | ||
|
||
await expect( | ||
db.video.findMany({ | ||
orderBy: { viewCount: 'desc' }, | ||
}) | ||
).resolves.toHaveLength(1); | ||
|
||
await expect( | ||
db.ratedVideo.findMany({ | ||
orderBy: { duration: 'asc' }, | ||
}) | ||
).resolves.toHaveLength(1); | ||
|
||
await expect( | ||
db.user.findMany({ | ||
orderBy: { assets: { _count: 'desc' } }, | ||
}) | ||
).resolves.toHaveLength(1); | ||
|
||
await expect( | ||
db.user.findUnique({ | ||
where: { id: user.id }, | ||
include: { | ||
ratedVideos: { | ||
orderBy: { | ||
viewCount: 'desc', | ||
}, | ||
}, | ||
}, | ||
}) | ||
).toResolveTruthy(); | ||
}); | ||
Comment on lines
+238
to
+271
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The new test case
Overall, the test case is a good start towards validating the new functionality but could be enhanced for more comprehensive testing and clarity.
|
||
|
||
it('update simple', async () => { | ||
const { db, videoWithOwner: video } = await setup(); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation of
buildWhereHierarchy
method correctly handles the transformation ofwhere
conditions to support fields inherited from base types. This is key to achieving the PR's objective of enhancing polymorphism support. However, there's a potential risk of prototype pollution due to direct manipulation of object properties without validating their names against a list of disallowed prototype properties. This could lead to unintended side effects if a user-controlled input is passed directly to this method.Consider adding a check to ensure that field names do not correspond to prototype properties, or use a
Map
for handling dynamic keys safely.