I'm working on synchronization entities from one DB to another. I have entities mapped for ORM and ODM, like:
/* * @ODM\Document( * repositoryClass="App\Lib\Repositories\ProductRepository", * collection="products" * ) * @ODM\InheritanceType("COLLECTION_PER_CLASS") * * @ORM\Entity( * repositoryClass="App\Lib\Repositories\Legacy\LegacyProductRepository" * ) * @ORM\Table(name="product") * * @ORM\HasLifecycleCallbacks() * @ODM\HasLifecycleCallbacks() */ class Product extends Article
It works nice, but I would like to load entity from document manager from mongo db and save it to ORM:
$product = $this->documentManager->find(Product::class, $id); $this->entityManager->merge($product); $this->entityManager->flush();
But I have an issue with relations. How do I persist related entity (such as ProductAction) with merging a product?
1 Answers
Answers 1
If I understand correctly, you want to merge "ProductAction" related entities to the ORM when a Product entity is merged to it.
You can use , cascade={"merge"}
on the relation., eg.
/** * @ORM\OneToMany(targetEntity="App\Entity\ProductAction", mappedBy="product", cascade={"persist", "merge"}) */ private $productActions;
0 comments:
Post a Comment