I’m working with Doctrine 2, and have an Address value object:
class Address
{
/** @var string */
protected $street;
/** @var string */
protected $city;
/** @var Application\Domain\Model\Country */
protected $country;
}
I need to store this Address in a PHP session (serialized), and retrieve it later on. When I then retrieve this value object, I want to have the Country object merged to the current Entity Manager, so that this Country is in sync with the current unit of work.
Is it possible to “merge” this value object to the current Entity Manager, as I would do on a regular entity with cascade="merge", to get the Country instance replaced with the current one?
I can obviously manually create another Address with a manually merged Country:
$address = $_SESSION['address'];
$country = $em->merge($address->getCountry());
$address = new Address($address->getStreet(), $address->getCity(), $country);
But I’m wondering if I’m missing a feature in Doctrine that would allow me to directly merge the VO instead?
As far as I know, there is currently no documented way to do that.