-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[DoctrineBridge] [WIP] Add comparator
option to UniqueEntity
constraint
#61224
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
base: 7.4
Are you sure you want to change the base?
[DoctrineBridge] [WIP] Add comparator
option to UniqueEntity
constraint
#61224
Conversation
Hey! I see that this is your first PR. That is great! Welcome! Symfony has a contribution guide which I suggest you to read. In short:
Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change. When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor! I am going to sit back now and wait for the reviews. Cheers! Carsonbot |
comparator
option to UniqueEntity
constraintcomparator
option to UniqueEntity
constraint
c6f6493
to
fe83cc8
Compare
comparator
option to UniqueEntity
constraintcomparator
option to UniqueEntity
constraint
comparator
option to UniqueEntity
constraintcomparator
option to UniqueEntity
constraint
If at all possible, can I get some feedback on this? I'm unsure how to proceed otherwise. |
src/Symfony/Bridge/Doctrine/Tests/Validator/Constraints/UniqueEntityValidatorTest.php
Outdated
Show resolved
Hide resolved
Thank you @OskarStark for spotting that! |
… and enforce use of only `identifierFieldNames` or `comparator` The `comparator` allows the `UniqueEntityValidator` to delegate the equality check to a user-defined callback. This helps in edge-cases where a simple equality check (after casting to string) of all `identifierFieldNames` is not enough.
67c9acd
to
dc900ea
Compare
This pull request adds a new configuration option
comparator
to theUniqueEntity
constraint. The callback, if supplied, is used instead of working throughidentifierFieldNames
, to establish equality between the found entity and the data on the validated object.This allows custom behavior in those edge-cases where the default equality check after stringification is not enough.
The following is an example of how this works:
Without such functionality, one currently has two options:
\Stringable
.Both are problematic in some cases:
Todos:
This being my first contribution I'm aware that I probably missed a few guidelines - though I tried to follow https://symfony.com/doc/current/contributing/code/pull_requests.html closely. Please don't hesitate to point those out, or if this functionality is in general not wanted!