Skip to content

Commit 241f709

Browse files
aradojeNyholm
authored andcommitted
Add sequence group example to documentation (#2)
* Add sequence group example to documentation * Update Readme.md
1 parent 81044e2 commit 241f709

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

Readme.md

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@ final class EmailUser
2121
{
2222
/**
2323
* @Assert\NotBlank
24-
* @Assert\Uuid
2524
* @EntityExist(entity="App\Entity\User")
2625
*
27-
* @var string UUID to user's id property
26+
* @var int User's id property
2827
*/
2928
private $user;
3029

@@ -39,6 +38,31 @@ final class EmailUser
3938
// ...
4039
```
4140

41+
In case you are using other constraints to validate the property before entity should be checked in the database (like `@Assert\Uuid`) you should use [Group sequence](https://symfony.com/doc/current/validation/sequence_provider.html) in order to avoid 500 errors from Doctrine mapping.
42+
43+
```php
44+
namespace App\Message\Command;
45+
46+
use Happyr\Validator\Constraint\EntityExist;
47+
use Symfony\Component\Validator\Constraints as Assert;
48+
49+
/**
50+
* @Assert\GroupSequence({"EmailUser", "DatabaseCall"})
51+
*/
52+
final class EmailUser
53+
{
54+
/**
55+
* @Assert\NotBlank
56+
* @Assert\Uuid
57+
* @EntityExist(entity="App\Entity\User", groups={"DatabaseCall"}, property="uuid")
58+
*
59+
* @var string Uuid
60+
*/
61+
private $user;
62+
63+
// ...
64+
```
65+
4266
## Install
4367

4468
```console
@@ -59,4 +83,4 @@ services:
5983
## Note
6084
6185
The Validator will not produce a violation when value is empty. This means that you should most likely use it in
62-
combination with `NotBlank`.
86+
combination with `NotBlank`.

0 commit comments

Comments
 (0)