lphuberdeau / Neo4j-PHP-OGM

A doctrine2 style library to access neo4j graphs
156 stars 45 forks source link

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

Open scott-r-lindsey opened 9 years ago

scott-r-lindsey commented 9 years ago

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?

lphuberdeau commented 9 years ago

I believe this behaviour is expected.

scott-r-lindsey commented 9 years ago

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?

lphuberdeau commented 9 years ago

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.