Open mmoreram opened 8 years ago
Can you make a gist containing the entities and persistance code leading to the error?
@zeroedin-bill Updated :)
Hmm. I haven't seen someone use interfaces as targetEntity before, but I really don't know what is going on here. @Ocramius, @guilhermeblanco, any ideas?
@zeroedin-bill the resolve target entity does the work :)
http://symfony.com/doc/current/cookbook/doctrine/resolve_target_entity.html
ping @acasademont
I got it. Look at this piece of code.
$categories = $product->getCategories();
$newCategories = new ArrayCollection();
foreach ($categories as $category) {
$newCategories->add($category);
}
$product->setCategories($newCategories);
What happens here? Even if categories are the same, because the object is no longer a PersistentCollection but an ArrayCollection, the element if marked as dirty and is recomputed again as inserts.
I would love to understand why, so I will continue digging in the project, but if you can give me some light, would be nice :)
@zeroedin-bill @Ocramius
@mmoreram I think we'd really need a failing test case to fully understand what's going on here...
Yes. That's what I working on now :)
:+1:
Scenario
The mapping code
We have the Purchasable mapping file (abstract one)
And we have the specific Product mapping file (Extends Purchasable)
The crashing code
This code is part of a service.
productObjectManager
can be considered as the default entity manager. The exception is produced by the second call.Some tips
When I do flush in the first time, the Collection of Category instances is set to dirty. After some investigation, https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/UnitOfWork.php#L607 this line is the one that set this value.
Commenting this line, everything works as expected (I know that that's not an option), but I would like to understand what implies this line and why is there.
Any help please? Any idea of what could be the issue?