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 theId
property (case-sensitive). -
This behavior can be changed by overwriting the
FindIdentityProperty
convention.
To do so, use thesetFindIdentityProperty
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();
});