-
-
Notifications
You must be signed in to change notification settings - Fork 12
fix: using _count in relation selection #143
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
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the ✨ Finishing Touches🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
|
Claude finished @ymc9's task —— View job Pull Request Review: fix: using _count in relation selection
|
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.
Pull Request Overview
This PR fixes the usage of _count in relation selection by properly handling cases where _count is selected within nested relation queries. The fix includes type safety improvements to prevent using _count on models without to-many relations and refactors code to extract count JSON building logic into a reusable method.
- Adds proper
_counthandling within relation selections in SQLite and PostgreSQL dialects - Refactors count JSON building logic from inline implementation to a shared
buildCountJsonmethod - Improves type safety by restricting
_countusage to models with to-many relations only
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/runtime/test/client-api/find.test.ts | Adds test cases for _count in relation selection and type error validation |
| packages/runtime/src/client/query-utils.ts | Changes field validation functions to use getField instead of requireField for safer field lookups |
| packages/runtime/src/client/crud/validator.ts | Simplifies to-many relations filtering by using Object.values and direct field references |
| packages/runtime/src/client/crud/operations/base.ts | Removes inline count JSON building logic and delegates to dialect's buildCountJson method |
| packages/runtime/src/client/crud/dialects/sqlite.ts | Adds _count handling in relation JSON building and renames parameter for consistency |
| packages/runtime/src/client/crud/dialects/postgresql.ts | Adds _count handling in relation JSON building and renames parameter for consistency |
| packages/runtime/src/client/crud/dialects/base.ts | Implements shared buildCountJson method extracted from operation handler |
| packages/runtime/src/client/crud-types.ts | Adds type constraint to only allow _count on models with to-many relations |

No description provided.