Skip to content

Commit 35ae166

Browse files
committed
Merge branch '5.4' into 6.2
* 5.4: [Form][Validator] Add new unique entity validation on form type
2 parents e8c9927 + cb7247a commit 35ae166

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

reference/constraints/UniqueEntity.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,29 @@ between all of the rows in your user table:
103103
}
104104
}
105105
106+
// src/Form/Type/UserType.php
107+
namespace App\Form\Type;
108+
109+
// ...
110+
// DON'T forget the following use statement!!!
111+
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
112+
113+
class UserType extends AbstractType
114+
{
115+
// ...
116+
117+
public function configureOptions(OptionsResolver $resolver): void
118+
{
119+
$resolver->setDefaults([
120+
// ...
121+
'data_class' => User::class,
122+
'constraints' => [
123+
new UniqueEntity(fields: ['email']),
124+
],
125+
]);
126+
}
127+
}
128+
106129
.. caution::
107130

108131
This constraint doesn't provide any protection against `race conditions`_.

0 commit comments

Comments
 (0)