[Validator] Allow Unique constraint validation on all elements#59274
Conversation
There was a problem hiding this comment.
Sometimes it could be useful to assert that every elements of a collection is not duplicated.
Is there a situation where it's better to have only the first error?
This PR adds a
multipleErrorsoption to the Unique constraint to avoid stopping at the first violation.
I think we can avoid adding a new option and simply modify the behavior in version 7.3.
That was my first idea but it will lead to a BC break like mentioned in #59037. |
|
|
||
| public array|string $fields = []; | ||
| public ?string $errorPath = null; | ||
| public bool $multipleErrors = false; |
There was a problem hiding this comment.
naming :) what about this? multipleErrors looks like a consequence of something, not an option
| public bool $multipleErrors = false; | |
| public bool $quickCheck = true; |
There was a problem hiding this comment.
The current name doesn't seem right to me. It's about having all errors, not necessarily multiple ones.
Maybe $allErrors?
If we want to name it closer to the behavior, the current one is "stopping on first error", which is more or less similar to PHPUnit --no-on-error flag.
So, another suggestion might be: $stopOnFirstError?
There was a problem hiding this comment.
Maybe "$all" so all must be unique?
There was a problem hiding this comment.
Agreed with $stopOnFirstError 👍
The PR updated in that way + CHANGELOG.md
|
|
||
| public array|string $fields = []; | ||
| public ?string $errorPath = null; | ||
| public bool $multipleErrors = false; |
There was a problem hiding this comment.
The current name doesn't seem right to me. It's about having all errors, not necessarily multiple ones.
Maybe $allErrors?
If we want to name it closer to the behavior, the current one is "stopping on first error", which is more or less similar to PHPUnit --no-on-error flag.
So, another suggestion might be: $stopOnFirstError?
8f36692 to
523d94e
Compare
523d94e to
3fc871e
Compare
|
Thank you @Jean-Beru. |
This PR was merged into the 7.3 branch. Discussion ---------- re-add accidentally removed changelog examples | Q | A | ------------- | --- | Branch? | 7.3 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | | License | MIT I gues removing these lines was not intended in #59274 Commits ------- 73ecbca re-add accidentally removed changelog examples
Sometimes it could be useful to assert that every elements of a collection is not duplicated. This PR adds a
multipleErrorsoption to the Unique constraint to avoid stopping at the first violation.Its value is
falseby default to avoid BC breaks:Now