I have an Address entity which is bind to a ZF / Laminas Form.
Some properties are defined. Such as street, country, ....
/**
* @var string
*
* @ORM\Column(type="string", length=2)
*/
protected $country;
/**
* @var float
*
* @ORM\Column(type="float", nullable=true)
*/
protected $longitude;
/**
* @var float
*
* @ORM\Column(type="float", nullable=true)
*/
protected $latitude;
And a non stored property to force a geolocation through an EventListener
/**
* @var bool
*/
protected $geolocation = true;
With accessors
/**
* @param bool $geolocation
*
* @return self
*/
public function setGeolocation(bool $geolocation): self
{
$this->geolocation = $geolocation;
return $this;
}
Problem is during hydration through accessors. Value of "geolocation" comes out from form in string type '1' or '0' (checkbox)
Hydration is proceed by the DoctrineObject hydrator but property is not managed by ORM. So with the strict type mode enabled, an exception is thrown because of setGeolocation() parameter type.
It should works with an @ORM\Column(type="boolean")
but I don't want to store this value.
How to define an entity property without create a column in db ?