Store column values of not cache-able associations#1302
Conversation
|
Hello, thank you for creating this pull request. I have automatically opened an issue http://www.doctrine-project.org/jira/browse/DDC-3566 We use Jira to track the state of pull requests and the versions they got |
There was a problem hiding this comment.
What if the entity is not in identity map?
There was a problem hiding this comment.
has it to be persisted somehow?
There was a problem hiding this comment.
I'm not an expert but I think some kind of proxy should be created to allow traversal of the association (that will obvisouly trigger another request).
There was a problem hiding this comment.
you are right! IdentifierFlattener is the answer (i hope)! I will try do do it
There was a problem hiding this comment.
Can you try to remove this line and make sure the test still passes? From your code, it seems that you are trying to extract the identifier from the association, but if the association is not cached, then this means the cache does not hold any identifier for the association, right?
|
It would be nice if you could also add the same kind of tests but for ManyToOne associations, to make sure it also work properly when there is no @Cache on the association. |
|
Done |
|
@goetas at first this seems very good. I may have looked too quickly, but do you mind ensuring there's a & TO_ONE association with composite keys and check if it works as a test case? |
|
I think that if I add a "good" association with multiple keys and nested association, the test will fail. Any chance to see #1113 merged before this? The mentioned PR contains a lot of improvements for composite keys that will be helpful to create a good test for this PR. |
|
@goetas did you try to run the test by commenting the line I've told in the comment? |
|
@bakura10 you mean this right? $this->assertNull($this->cache->getEntityCacheRegion(Client::CLASSNAME));
$this->assertInstanceOf('Doctrine\ORM\Cache\Region', $this->cache->getEntityCacheRegion(Token::CLASSNAME));
$client = new Client('FabioBatSilva');
$token = new Token('token-hash', $client);
$this->_em->persist($client);
$this->_em->persist($token);
$this->_em->flush();
$this->_em->clear();
$queryCount = $this->getCurrentQueryCount();
$this->assertTrue($this->cache->containsEntity(Token::CLASSNAME, $token->getToken()));
$this->assertFalse($this->cache->containsEntity(Client::CLASSNAME, $client->getId()));
$entity = $token;
//$entity = $this->_em->find(Token::CLASSNAME, $token->getToken());
$this->assertInstanceOf(Token::CLASSNAME, $entity);
$this->assertInstanceOf(Client::CLASSNAME, $entity->getClient());
$this->assertEquals('token-hash', $entity->getToken());
$this->assertEquals($queryCount, $this->getCurrentQueryCount());
$this->assertEquals('FabioBatSilva', $entity->getClient()->getName());
$this->assertEquals($queryCount, $this->getCurrentQueryCount());
//$this->assertEquals($queryCount + 1, $this->getCurrentQueryCount());With this, the test is green. |
|
Nope, you need to uncomment the ->clear() call. Actually the use case is the following: in first request, the entity is put in cache, in next request, obviously no object is in identity map. |
|
@bakura10 I have edited my previous comment. Even for this version, tests are green. It it ok? |
|
Yep, sounds nice :D. |
|
I just do not understand what happen under the hood. It seems that you are retrieving the association from the id, but in the case, the id does not exist because it has not been put into the cache. |
|
@bakura10 I've edited the |
|
But you are not supposed to put the id in cache if @Cache is not present in the association. For instance, if the client of the token is modified on the token, then you will retrieve an out-of-date association ID (or maybe Doctrine is smart enough to invalidate the cache whenever the entity is updated). |
There was a problem hiding this comment.
Please remove all unnecessary API
There was a problem hiding this comment.
The addToken method is used to create easily the link between "action" and "token" instances
|
green :) Even with foreign entities as keys |
|
@Ocramius I have updated the test suite |
There was a problem hiding this comment.
@guilhermeblanco To be honest I'm not sure that this approach will work with nested composite keys & associations
Store column values of not cache-able associations
|
👍 |
Fixes #1301