Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions reference/constraints/UniqueEntity.rst
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,59 @@

.. include:: /reference/constraints/_groups-option.rst.inc

``identifierFieldNames``
~~~~~~~~~~~~~~~~~~~~~~~~

**type**: ``array`` **default**: ``null``

When updating an entity through a PHP class (e.g. DTOs), this option can be used to
define the class properties that are used as the Doctrine entity key (or composite key).

Consider this Doctrine entity ::

// src/Entity/User.php
namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;

Check failure on line 290 in reference/constraints/UniqueEntity.rst

View workflow job for this annotation

GitHub Actions / Code Blocks

[Missing class] Class, interface or trait with name "Doctrine\ORM\Mapping" does not exist

#[ORM\Entity]
class User
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private int $id;

#[ORM\Column]
private string $name;
}

// ... getter and setter methods

For exemple, in a :doc:`Messenger component </components/messenger>` message that
updates ``User`` entities, you can check its uniqueness by defining its identifier::

// src/Message/UpdateEmployeeProfile
namespace App\Message;

use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;

#[UniqueEntity(
fields: ['name'],
entityClass: User::class,
// 'uid' is the property name in the PHP class and 'id' is the name of
// the Doctrine entity property used as the primary key
identifierFieldNames: ['uid' => 'id'],
)]
class UpdateEmployeeProfile
{
public function __construct(
private string $uid,
private string $name,
) {
}
}

``ignoreNull``
~~~~~~~~~~~~~~

Expand Down
Loading