Skip to content

Commit a576a49

Browse files
committed
validate null (Expression constraint in 2.6)
Since Symfony 2.6, the Expression constraint doesn't skip validating `null` values.
1 parent 1ea6304 commit a576a49

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

reference/constraints/Expression.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,18 @@ One way to accomplish this is with the Expression constraint:
128128
// ...
129129
}
130130
131+
.. versionadded:: 2.6
132+
Since Symfony 2.6, the Expression constraint doesn't skip ``null`` values.
133+
134+
Before Symfony 2.6, the Expression constraint didn't validate ``null`` values.
135+
To preserve this behavior, you'll have to allow ``null`` values explicitly.
136+
For example, to allow blog posts without a category, your expression will
137+
look like this:
138+
139+
.. code-block:: text
140+
141+
this.getCategory() === null or this.getCategory() in ["php", "symfony"] or !this.isTechnicalPost()
142+
131143
The :ref:`expression <reference-constraint-expression-option>` option is the
132144
expression that must return true in order for validation to pass. To learn
133145
more about the expression language syntax, see

0 commit comments

Comments
 (0)