Doctrine2 should automatically merge related objects

I create an ordering process in which an object Orderis created using many steps. After each step, I put the partially completed object Orderin session, and in the last step I save it in the database.

During the steps, I load other (already existing) related objects into my object Order(for example, DiscountCoupon). The problem is that when I save Orderto sessionand then load it in the next step, all related objects will be detached. Therefore, when I want to store it in the database, it EntityManagerthrows an exception that requests installation cascade=persistin relation.

Of course, I do not need to save these objects (they are already in the database). An obvious solution may be to change the related objects with the combined ones (using the method EntityManager#merge), however, I have a rather complicated structure of objects with several levels of embedded objects, so the execution of the above process will be rather inconvenient.

Could Doctrine automatically complete this task for me? Therefore, instead of "complaining" about my individual objects, he can automatically combine them.

+3
source share
1 answer

As far as I can tell, you would create serious magic if you tried to make it fully automatic.

: mergeOrderEntities ($ Order, $EntityManager), , Order EntityManager:: merge() .

, , . , , , , .

0

All Articles