- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 111
fix: generated prisma schema contains error when using "@@unique" with base field #1766
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
…h base field Fixes #1758
📝 WalkthroughWalkthroughThe pull request introduces enhancements to the Changes
Assessment against linked issues
Possibly related PRs
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (2)
tests/regression/tests/issue-1758.test.ts (2)
5-27
: LGTM: Assertion correctly validates the expected error.The test assertion appropriately checks for the expected error message when attempting to use an inherited field in a @@unique constraint for a polymorphic model. This correctly validates the behavior described in issue #1758.
Consider adding a comment explaining the significance of this error message for improved clarity:
// Ensure that the system correctly identifies the invalid use of inherited fields in @@unique constraints for polymorphic models await expect( loadModelWithError( // ... model definition ... ) ).resolves.toContain('Cannot use fields inherited from a polymorphic base model in `@@unique`');
1-29
: Great job: Effective regression test for issue #1758.This test case effectively addresses the problem reported in issue #1758. It accurately models the scenario where a polymorphic model attempts to use an inherited field in a @@unique constraint, and correctly validates that the system identifies this as an error. The test is well-structured, concise, and focused on the specific issue at hand.
To further strengthen the test suite:
- Consider adding additional test cases to cover variations of this scenario, such as:
- Multiple levels of inheritance
- Different combinations of fields in the @@unique constraint
- Ensure that this test is included in the CI/CD pipeline to prevent regression in future updates.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (2)
- packages/schema/src/language-server/validator/attribute-application-validator.ts (2 hunks)
- tests/regression/tests/issue-1758.test.ts (1 hunks)
🧰 Additional context used
🔇 Additional comments (5)
tests/regression/tests/issue-1758.test.ts (3)
1-1
: LGTM: Import statement is correct.The import of
loadModelWithError
from '@zenstackhq/testtools' is appropriate for this test case.
3-4
: LGTM: Test structure is well-defined.The test suite and case are properly structured using Jest conventions. The naming clearly indicates the purpose of the test, and the use of an async test is appropriate for the asynchronous nature of the
loadModelWithError
function.
7-25
: LGTM: Model definition accurately represents the issue scenario.The model definition correctly implements the polymorphic relationship between Content and Store models, and includes the @@unique constraint that combines fields from both the base and extended models. This accurately represents the scenario described in issue #1758, making it an appropriate test case for the reported problem.
packages/schema/src/language-server/validator/attribute-application-validator.ts (2)
18-24
: Imports added correctly for new functionalityThe necessary functions have been correctly imported to support the added validation logic.
173-197
:⚠️ Potential issuePotential conflict with PR objective: Validation prevents using inherited fields in
@@unique
constraintsThe new
_checkUnique
method introduces a validation that disallows using fields inherited from a polymorphic base model in@@unique
attributes (lines 187-191). However, the PR aims to allow@@unique
constraints to include fields from both base and extended models, resolving issue #1758 where inherited fields were not recognized.This validation may prevent the desired functionality and contradict the PR's purpose.
Consider revising the validation logic to allow inherited fields in
@@unique
constraints. You may consider removing the check that triggers the error when inherited fields are used.Apply this diff to remove the blocking validation:
if (!isDataModelField(item.target.ref)) { accept('error', `Expecting a field reference`, { node: item }); return; } - if (item.target.ref.$container !== attr.$container && isDelegateModel(item.target.ref.$container)) { - accept('error', `Cannot use fields inherited from a polymorphic base model in \`@@unique\``, { - node: item, - }); - }
Fixes #1758