@@ -12,6 +12,7 @@ using an email address that already exists in the system.
12
12
| | - `message `_ |
13
13
| | - `em `_ |
14
14
| | - `repositoryMethod `_ |
15
+ | | - `errorPath `_ |
15
16
| | - `ignoreNull `_ |
16
17
+----------------+-------------------------------------------------------------------------------------+
17
18
| Class | :class: `Symfony\\ Bridge\\ Doctrine\\ Validator\\ Constraints\\ UniqueEntity ` |
@@ -151,15 +152,75 @@ The name of the repository method to use for making the query to determine the
151
152
uniqueness. If it's left blank, the ``findBy `` method will be used. This
152
153
method should return a countable result.
153
154
155
+ errorPath
156
+ ~~~~~~~~~
157
+
158
+ **type **: ``string `` **default **: ``The name of the first `` `field `_
159
+
154
160
.. versionadded :: 2.1
155
- The ``ignoreNull `` option was added in Symfony 2.1.
161
+ The ``errorPath `` option was added in Symfony 2.1.
162
+
163
+ If the entity violates against this constraint the error message is bound to
164
+ the first field. If there are more than one fields it may be desired to bind the
165
+ error message to another field.
166
+
167
+ Consider this example:
168
+
169
+ .. configuration-block ::
170
+
171
+ .. code-block :: yaml
172
+
173
+ # src/Acme/AdministrationBundle/Resources/config/validation.yml
174
+ Acme\AdministrationBundle\Entity\Service :
175
+ constraints :
176
+ - Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity :
177
+ fields : [ host, port ]
178
+ errorPath : port
179
+ message : ' This port is already in use on that host.'
180
+
181
+ .. code-block :: php-annotations
182
+
183
+ namespace Acme\AdministrationBundle\Entity;
184
+
185
+ use Doctrine\ORM\Mapping as ORM;
186
+ use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
187
+
188
+ /**
189
+ * @ORM\Entity
190
+ * @UniqueEntity(
191
+ * fields={"host", "port"},
192
+ * errorPath="port",
193
+ * message="This port is already in use on that host."
194
+ * )
195
+ */
196
+ class Service
197
+ {
198
+ /**
199
+ * @ORM\ManyToOne(targetEntity="Host")
200
+ */
201
+ public $host;
202
+
203
+ /**
204
+ * @ORM\Column(type="integer")
205
+ */
206
+ public $port;
207
+ }
208
+
209
+ Now, the message would be bound to the form field of the `port ` with this configuration.
210
+
156
211
157
212
ignoreNull
158
213
~~~~~~~~~~
159
214
160
215
**type **: ``Boolean `` **default **: ``true ``
161
216
217
+ .. versionadded :: 2.1
218
+ The ``ignoreNull `` option was added in Symfony 2.1.
219
+
162
220
If this option is set to ``true ``, then the constraint will allow multiple
163
221
entities to have a ``null `` value for a field without failing validation.
164
222
If set to ``false ``, only one ``null `` value is allowed - if a second entity
165
223
also has a ``null `` value, validation would fail.
224
+
225
+
226
+ .. _`field` : `fields `_
0 commit comments