Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Validator] Allow Unique constraint validation on all elements#59274

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

Jean-Beru
Copy link
Contributor

QA
Branch?7.3
Bug fix?no
New feature?yes
Deprecations?no
Issues
LicenseMIT

Sometimes it could be useful to assert that every elements of a collection is not duplicated. This PR adds amultipleErrors option to the Unique constraint to avoid stopping at the first violation.

Its value isfalse by default to avoid BC breaks:

$violations =$this->validator->validate(    ['a1','a2','a1','a1','a2'],newUnique(),);// 1 violation on [2]

Now

$violations =$this->validator->validate(    ['a1','a2','a1','a1','a2'],newUnique(multipleErrors:true),);// 3 violations on [2], [3] and [4]

Crovitche-1623 and OskarStark reacted with thumbs up emoji
Copy link
Member

@GromNaNGromNaN left a comment
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

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 amultipleErrors option 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.

@Jean-Beru
Copy link
ContributorAuthor

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 amultipleErrors option 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.

@@ -26,6 +26,7 @@ class Unique extends Constraint

public array|string $fields = [];
public ?string $errorPath = null;
public bool $multipleErrors = false;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

naming :) what about this? multipleErrors looks like a consequence of something, not an option

Suggested change
public bool$multipleErrors =false;
public bool$quickCheck =true;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

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?

mtarld and Jean-Beru reacted with thumbs up emoji
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Maybe "$all" so all must be unique?

Copy link
ContributorAuthor

@Jean-BeruJean-BeruFeb 6, 2025
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Agreed with$stopOnFirstError 👍

The PR updated in that way +CHANGELOG.md

@@ -26,6 +26,7 @@ class Unique extends Constraint

public array|string $fields = [];
public ?string $errorPath = null;
public bool $multipleErrors = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

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?

mtarld and Jean-Beru reacted with thumbs up emoji
@nicolas-grekas
Copy link
Member

Thank you@Jean-Beru.

@nicolas-grekasnicolas-grekas merged commitfd9c5b4 intosymfony:7.3Feb 12, 2025
8 of 10 checks passed
@Jean-BeruJean-Beru deleted the fix-unique-constraint branchMarch 4, 2025 10:30
@fabpotfabpot mentioned this pull requestMay 2, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@OskarStarkOskarStarkOskarStark left review comments

@fabpotfabpotfabpot requested changes

@nicolas-grekasnicolas-grekasnicolas-grekas approved these changes

@GromNaNGromNaNGromNaN approved these changes

@mtarldmtarldmtarld approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
7.3
Development

Successfully merging this pull request may close these issues.

7 participants
@Jean-Beru@nicolas-grekas@fabpot@GromNaN@OskarStark@mtarld@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp