DDC-446: Cached resultset do not add Entities in UnitOfWork #4947

Closed
doctrinebot opened this Issue Mar 19, 2010 · 11 comments

1 participant

@doctrinebot

Jira issue originally created by user @guilhermeblanco:

When using resultset cache, when you fetch for these object and attempt to manipulate them, they fail to work giving this message:

Notice:  Undefined index: 000000006f95482300000000384dffac in /srv/app/library/Doctrine/ORM/UnitOfWork.php on line 1901
@doctrinebot

Comment created by romanb:

Objects coming from the result cache are all detached. The EM does not care about them unless you merge() them. But there should probably be a better exception instead of this notice. Please show the code that causes the notice.

PS: Result caching objects is inefficient.

@doctrinebot

Comment created by @guilhermeblanco:

Test case attached.

This is a situation where it should work smoothly IMHO.

@doctrinebot

Comment created by romanb:

No, it should not work smoothly because $user is a detached object. It should throw an exception but the problem is that its hard to detect whether an object is detached in _doPersist.

@doctrinebot

Comment created by romanb:

You need to understand the difference between managed and detached. Its very important.

@doctrinebot

Comment created by @guilhermeblanco:

Adding merge doesn't work too.... same error.

Juyst add $this->_em->merge($user); in line 52.

@doctrinebot

Comment created by romanb:

Of course it wouldnt because thats not how merge works. Merge returns a managed copy.

So you would do:

$managedUser = $this->_em->merge($user);

...

$article->setUser($managedUser);

...
@doctrinebot

Comment created by @beberlei:

Implemented through DDC-217

@doctrinebot

Issue was closed with resolution "Fixed"

@doctrinebot doctrinebot added this to the 2.2 milestone Dec 6, 2015
@doctrinebot doctrinebot closed this Dec 6, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment