Doctrine 2: Reassigning Objects Through Value Objects

I am working with Doctrine 2 and has an Address value object:

 class Address { /** @var string */ protected $street; /** @var string */ protected $city; /** @var Application\Domain\Model\Country */ protected $country; } 

I need to save this Address in a PHP session (serialized) and get it later. When I get this value object, I want the Country object to be combined with 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 with the current Entity Manager, as I would do on a regular object with cascade="merge" to replace the Country instance with the current one?

I can manually create another Address with manually combined Country :

 $address = $_SESSION['address']; $country = $em->merge($address->getCountry()); $address = new Address($address->getStreet(), $address->getCity(), $country); 

But I wonder if there is a lack of function in Doctrine that would allow me to directly merge VO?

+4
source share
1 answer

As far as I know, there is currently no documented way to do this.

+1
source

Source: https://habr.com/ru/post/1388683/


All Articles