mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
DDC-2496: Unexpected behaviour flushing single entity #3136
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @doctrinebot on GitHub (Jun 10, 2013).
Originally assigned to: @Ocramius on GitHub.
Jira issue originally created by user hrajchert:
The following works as expected:
$existingElement = $repository->find(1);
$existingElement->setSomething('foo');
$newElement = new Element('bar');
$em->persist($newElement);
$em->flush($newElement);
// The new element is added and the existing is not modified
The following does not:
$existingElement = $repository->find(1);
$em->remove(existingElement);
$newElement = new Element('bar');
$em->persist($newElement);
$em->flush($newElement);
// The new element is added and the existing is deleted (i didnt flush THAT element)
The following does not:
$newElement2 = new Element('foo');
$em->persist($newElement2);
$newElement = new Element('bar');
$em->persist($newElement);
$em->flush($newElement);
// Both elements are persisted, even if I only flushed $newElement
@doctrinebot commented on GitHub (Jun 12, 2013):
Comment created by hrajchert:
By the way, I noticed in the code that this seems to be "expected behaviour", but it doesn't make too much sense, as the idea is to not disturb the original unit of work.
The problem arises when I call some findOrCreate methods that I've done. The idea is that those entities should be there, but not always are, and they usually occur on the middle of some other processing, so if I have some new elements before calling the findOrCreate I dont want them to be inserted until I flush them in particular.
Right now Im creating a new EntityManager (which involves a new connection), doing the insert there and then merging into the other EntityManager, but the merge is very error prone to the order you merge stuff.
@doctrinebot commented on GitHub (Jun 12, 2013):
Comment created by @ocramius:
Flushing with a given parameter is only about optimizing changeset computation - it is not meant to flush only the new element.
@doctrinebot commented on GitHub (Jun 12, 2013):
Issue was closed with resolution "Invalid"
@doctrinebot commented on GitHub (Jun 17, 2013):
Comment created by hrajchert:
So how would you recommend to resolve the findOrCreate issues?
@doctrinebot commented on GitHub (Jun 17, 2013):
Comment created by @ocramius:
You would have to flush afterwards.