We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e6f9e62 commit fc94456Copy full SHA for fc94456
reference/constraints/UniqueEntity.rst
@@ -126,6 +126,29 @@ between all of the rows in your user table:
126
}
127
128
129
+ // src/Form/Type/UserType.php
130
+ namespace App\Form\Type;
131
+
132
+ // ...
133
+ // DON'T forget the following use statement!!!
134
+ use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
135
136
+ class UserType extends AbstractType
137
+ {
138
139
140
+ public function configureOptions(OptionsResolver $resolver): void
141
142
+ $resolver->setDefaults([
143
144
+ 'data_class' => User::class,
145
+ 'constraints' => [
146
+ new UniqueEntity(fields: ['email']),
147
+ ],
148
+ ]);
149
+ }
150
151
152
.. caution::
153
154
This constraint doesn't provide any protection against `race conditions`_.
0 commit comments