Neo4j-PHP-OGM icon indicating copy to clipboard operation
Neo4j-PHP-OGM copied to clipboard

$em->flush() is not supposed to effect which entities are managed

Open scott-r-lindsey opened this issue 9 years ago • 3 comments

So, if I do the following:

$x = new X;
$em->persist($x); 

$em->flush();  // this updates $x in the Neo4j, as I would expect...

$x->setFoo('bar');

$em->flush(); // $x should update

But it doesn't work unless I add another $em->persist($x) after the flush. I would expect that flush() would not effect which entities are managed, but it seems that flushing is effectively executing a clear() as a side effect.

Are my expectations out of whack or is this a bug?

scott-r-lindsey avatar Nov 09 '15 23:11 scott-r-lindsey

I believe this behaviour is expected.

lphuberdeau avatar Nov 10 '15 13:11 lphuberdeau

Well I'm looking for some explicit documentation but not really finding it! It just seems to be assumed.

I'm not going to call the behavior wrong -- It's your OGM -- but it definitely differs from Doctrine or MongoODM.

And it seems a little hard to work with. If you break your application up into lots of little components (per the Symfony way), one of them might need to write data, and it should be able to do so without un-persisting objects that the controller expects to hand to twig (because then twig will not be able to lazy-load relations).

I wonder if the fix is as simple as removing one or two lines?

scott-r-lindsey avatar Nov 10 '15 15:11 scott-r-lindsey

Is twig really unable to lazy-load relations after a flush()?

This is all a long time ago, but from what I recall, the persist list was really just a list of things to persist on the next flush.

Feel free to experiment and see what breaks if you remove the explicit clear. I guess it could also be made optional.

lphuberdeau avatar Nov 10 '15 15:11 lphuberdeau