Session: How to Customize the Identity Property Lookup for Entities

  • When a client handles an entity, it must know which property is the entity's identifier.
    By default, the client always looks for the Id property (case-sensitive).

  • This behavior can be changed by overwriting the FindIdentityProperty convention.
    To do so, use the setFindIdentityProperty method.

Syntax

public function setFindIdentityProperty(?Closure $findIdentityProperty): void;

Example

The simplest example would be to check if the property name is equal to 'Identifier'.

$store->getConventions()->setFindIdentityProperty(function($property) {
        return "Identifier" == $property->getName();
});