File tree Expand file tree Collapse file tree 1 file changed +53
-0
lines changed Expand file tree Collapse file tree 1 file changed +53
-0
lines changed Original file line number Diff line number Diff line change @@ -274,6 +274,59 @@ each with a single field.
274
274
275
275
.. include :: /reference/constraints/_groups-option.rst.inc
276
276
277
+ ``identifierFieldNames ``
278
+ ~~~~~~~~~~~~~~~~~~~~~~~~
279
+
280
+ **type **: ``array `` **default **: ``null ``
281
+
282
+ When updating an entity through a PHP class (e.g. DTOs), this option can be used to
283
+ define the class properties that are used as the Doctrine entity key (or composite key).
284
+
285
+ Consider this Doctrine entity ::
286
+
287
+ // src/Entity/User.php
288
+ namespace App\Entity;
289
+
290
+ use Doctrine\ORM\Mapping as ORM;
291
+
292
+ #[ORM\Entity]
293
+ class User
294
+ {
295
+ #[ORM\Id]
296
+ #[ORM\GeneratedValue]
297
+ #[ORM\Column]
298
+ private int $id;
299
+
300
+ #[ORM\Column]
301
+ private string $name;
302
+ }
303
+
304
+ // ... getter and setter methods
305
+
306
+ For exemple, in a :doc: `Messenger component </components/messenger >` message that
307
+ updates ``User `` entities, you can check its uniqueness by defining its identifier::
308
+
309
+ // src/Message/UpdateEmployeeProfile
310
+ namespace App\Message;
311
+
312
+ use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
313
+
314
+ #[UniqueEntity(
315
+ fields: ['name'],
316
+ entityClass: User::class,
317
+ // 'uid' is the property name in the PHP class and 'id' is the name of
318
+ // the Doctrine entity property used as the primary key
319
+ identifierFieldNames: ['uid' => 'id'],
320
+ )]
321
+ class UpdateEmployeeProfile
322
+ {
323
+ public function __construct(
324
+ private string $uid,
325
+ private string $name,
326
+ ) {
327
+ }
328
+ }
329
+
277
330
``ignoreNull ``
278
331
~~~~~~~~~~~~~~
279
332
You can’t perform that action at this time.
0 commit comments