-
Notifications
You must be signed in to change notification settings - Fork 232
Fix UniqueValidator with new identifierFieldNames
parameter
#918
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
identifierFieldNames
parameter
β¦ instead of overriding the contructor
I completely revised the implementation. In fact, we don't have to override the constructor to change only the default value of the We have to declare the class conditionally to keep the compatibility with Symfony 6.4 as the prop type has been added in 7.0. |
Property Doctrine\Bundle\MongoDBBundle\Validator\Constraints\Unique::$service overriding property Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity::$service (string) should also have native type string. https://github.com/phpstan/phpstan-src/blob/f4e4354045c2ed972ff3c4ad927fcad539a8a338/src/Rules/Properties/OverridingPropertyRule.php#L168-L176
#[Attribute(Attribute::TARGET_CLASS | Attribute::IS_REPEATABLE)] | ||
class Unique extends UniqueEntity | ||
{ | ||
if ((new ReflectionProperty(UniqueEntity::class, 'service'))->hasType()) { |
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.
Noted that this is essentially a test for Symfony 7.0+ based on symfony/symfony@7ea2461 adding parameter types to UniqueEntity.
@@ -23,11 +25,71 @@ public function testWithDefaultProperty(): void | |||
self::assertInstanceOf(Unique::class, $constraint); | |||
self::assertSame(['email'], $constraint->fields); | |||
self::assertSame('doctrine_odm.mongodb.unique', $constraint->validatedBy()); | |||
self::assertNull($constraint->em); |
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.
I'm not questioning the correctness here, but why was a $constraint->em
assertion introduced?
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.
I hit an issue while working on the previous implementation.
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.
It would have been so nice if this parameter was named manager
to take into account the ODM.
Thank you @soyuka for raising the issue again and proposing a solution. |
thanks @GromNaN for taking this over my dirty patch :D |
Fix #874
Breaking change in Symfony symfony/symfony#38662