8000 bug #3593 Clarified Default and ClassName groups (WouterJ) · symfony/symfony-docs@0ab1f24 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0ab1f24

Browse files
committed
bug #3593 Clarified Default and ClassName groups (WouterJ)
This PR was merged into the 2.3 branch. Discussion ---------- Clarified Default and ClassName groups This is still the most difficult part of the validation groups and we don't put much attention on it. I've refactored it a bit after the really great explaination of @webmozart. For more information see: symfony/symfony#10287 (comment) | Q | A | --- | --- | Doc fix? | yes | New docs? | yes | Applies to | all | Fixed tickets | - Commits ------- b6357fa Updated after review of @webmozart 2330cd8 Clarified Default vs ClassName groups
2 parents 6d1378e + b6357fa commit 0ab1f24

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

book/validation.rst

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -807,11 +807,13 @@ user registers and when a user updates their contact information later:
807807
}
808808
}
809809
810-
With this configuration, there are two validation groups:
810+
With this configuration, there are three validation groups:
811811

812-
* ``User`` - contains the constraints that belong to no other group,
813-
and is considered the ``Default`` group. (This group is useful for
814-
:ref:`book-validation-group-sequence`);
812+
* ``Default`` - contains the constraints in the current class and all
813+
referenced classes that belong to no other group;
814+
815+
* ``User`` - equivalent to all constraints of the ``User`` object in the
816+
``Default`` group;
815817

816818
* ``registration`` - contains the constraints on the ``email`` and ``password 8000 ``
817819
fields only.
@@ -837,13 +839,8 @@ Group Sequence
837839
--------------
838840

839841
In some cases, you want to validate your groups by steps. To do this, you can
840-
use the ``GroupSequence`` feature. In the case, an object defines a group sequence,
841-
and then the groups in the group sequence are validated in order.
842-
843-
.. tip::
844-
845-
Group sequences cannot contain the group ``Default``, as this would create
846-
a loop. Instead, use the group ``{ClassName}`` (e.g. ``User``).
842+
use the ``GroupSequence`` feature. In this case, an object defines a group sequence
843+
, which determines the order groups should be validated.
847844

848845
For example, suppose you have a ``User`` class and want to validate that the
849846
username and the password are different only if all other validation passes
@@ -968,6 +965,20 @@ In this example, it will first validate all constraints in the group ``User``
968965
(which is the same as the ``Default`` group). Only if all constraints in
969966
that group are valid, the second group, ``Strict``, will be validated.
970967

968+
.. caution::
969+
970+
As you have already seen in the previous section, the ``Default`` group
971+
and the group containing the class name (e.g. ``User``) were identical.
972+
However, when using Group Sequences, they are no longer identical. The
973+
``Default`` group will now reference the group sequence, instead of all
974+
constraints that do not belong to any group.
975+
976+
This means that you have to use the ``{ClassName}`` (e.g. ``User``) group
977+
when specifing a group sequence. When using ``Default``, you get an
978+
infinite recursion (as the ``Default`` groups references the group
979+
sequence, which will contain the ``Default`` group which references the
980+
same group sequence, ...).
981+
971982
Group Sequence Providers
972983
~~~~~~~~~~~~~~~~~~~~~~~~
973984

0 commit comments

Comments
 (0)
0