-
-
Notifications
You must be signed in to change notification settings - Fork 484
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
fix: add UniqueEntity constraint to email field. #1562
fix: add UniqueEntity constraint to email field. #1562
Conversation
The email property is defined as unique in the DB, so we need to constraint the field to unique in the form in order to prevent a UniqueConstraintViolationException exception.
i see this a bit critical, for one of my projects i need to have users with different ids but with same email it is easy to overwrite the doctrine setting for uniq column, but it isn't possible to remove unique entry validation. |
As long as we define the property as unique in database, we should be consistent and add an annotation IMHO. How do you override the unique definition ? It could be interesting to see if you cannot override the annotation too. |
For ORM,
for Validator:
the other contraints have groups like "Registration", the new one has not. Also it should probably be better configured where the Validation Groups are used. |
Indeed since there is validation group everywhere we should use it too. Does adding
would solve your issue @Hanmac ? |
i would need to debug it, but i could work with that i think |
If you have time to try in order to confirm it, it would be great. This would avoid us to block you ^^ |
So, to add validation group, I just need to remove the line (24) <constraint name="Email">
<option name="groups">
<value>Registration</value>
<value>Profile</value>
</option>
</constraint> block in the code. Am I right ? (I tested of course, unique validation on email still works with the line removed). |
src/Resources/config/validation.xml
Outdated
@@ -18,6 +21,7 @@ | |||
</constraint> | |||
</property> | |||
<property name="email"> | |||
<constraint name="Email"/> |
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.
This line could be removed.
src/Resources/config/validation.xml
Outdated
@@ -1,6 +1,13 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> | |||
<constraint-mapping xmlns="http://symfony.com/schema/dic/constraint-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/constraint-mapping http://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd"> | |||
<class name="Sonata\UserBundle\Model\User"> | |||
<constraint name="Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity"> | |||
<option name="fields">email</option> | |||
<option name="groups"> |
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.
<option name="groups"> | |
<option name="groups"> |
I'm not sure but the indent seems weird
Subject
This PR add
UniqueEntity
constraint to email field in validation.xml.Why :
The email property is defined as unique in the DB, so we need to
constraint the field to unique in the form in order to prevent a
UniqueConstraintViolationException
exception.I am targeting this branch, because it is BC.
Changelog