Merge pull request #1447 from krispypen/patch-1
Fix second level caching for queries with multiple joins
This commit is contained in:
commit
96b065b282
@ -259,7 +259,8 @@ class DefaultQueryCache implements QueryCache
|
|||||||
}
|
}
|
||||||
|
|
||||||
// @TODO - move to cache hydration components
|
// @TODO - move to cache hydration components
|
||||||
foreach ($rsm->relationMap as $name) {
|
foreach ($rsm->relationMap as $alias => $name) {
|
||||||
|
$metadata = $this->em->getClassMetadata($rsm->aliasMap[$rsm->parentAliasMap[$alias]]);
|
||||||
$assoc = $metadata->associationMappings[$name];
|
$assoc = $metadata->associationMappings[$name];
|
||||||
|
|
||||||
if (($assocValue = $metadata->getFieldValue($entity, $name)) === null || $assocValue instanceof Proxy) {
|
if (($assocValue = $metadata->getFieldValue($entity, $name)) === null || $assocValue instanceof Proxy) {
|
||||||
|
@ -150,6 +150,51 @@ class DefaultQueryCacheTest extends OrmTestCase
|
|||||||
$this->assertInstanceOf('Doctrine\ORM\Cache\QueryCacheKey', $this->region->calls['put'][8]['key']);
|
$this->assertInstanceOf('Doctrine\ORM\Cache\QueryCacheKey', $this->region->calls['put'][8]['key']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testPutToOneAssociation2LevelsQueryResult()
|
||||||
|
{
|
||||||
|
$result = array();
|
||||||
|
$uow = $this->em->getUnitOfWork();
|
||||||
|
$key = new QueryCacheKey('query.key1', 0);
|
||||||
|
$rsm = new ResultSetMappingBuilder($this->em);
|
||||||
|
$cityClass = $this->em->getClassMetadata(City::CLASSNAME);
|
||||||
|
$stateClass = $this->em->getClassMetadata(State::CLASSNAME);
|
||||||
|
$countryClass = $this->em->getClassMetadata(Country::CLASSNAME);
|
||||||
|
|
||||||
|
$rsm->addRootEntityFromClassMetadata(City::CLASSNAME, 'c');
|
||||||
|
$rsm->addJoinedEntityFromClassMetadata(State::CLASSNAME, 's', 'c', 'state', array('id'=>'state_id', 'name'=>'state_name'));
|
||||||
|
$rsm->addJoinedEntityFromClassMetadata(Country::CLASSNAME, 'co', 's', 'country', array('id'=>'country_id', 'name'=>'country_name'));
|
||||||
|
|
||||||
|
for ($i = 0; $i < 4; $i++) {
|
||||||
|
$country = new Country("Country $i");
|
||||||
|
$state = new State("State $i", $country);
|
||||||
|
$city = new City("City $i", $state);
|
||||||
|
|
||||||
|
$result[] = $city;
|
||||||
|
|
||||||
|
$cityClass->setFieldValue($city, 'id', $i);
|
||||||
|
$stateClass->setFieldValue($state, 'id', $i*2);
|
||||||
|
$countryClass->setFieldValue($country, 'id', $i*3);
|
||||||
|
|
||||||
|
$uow->registerManaged($country, array('id' => $country->getId()), array('name' => $country->getName()));
|
||||||
|
$uow->registerManaged($state, array('id' => $state->getId()), array('name' => $city->getName(), 'country' => $country));
|
||||||
|
$uow->registerManaged($city, array('id' => $city->getId()), array('name' => $city->getName(), 'state' => $state));
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->assertTrue($this->queryCache->put($key, $rsm, $result));
|
||||||
|
$this->assertArrayHasKey('put', $this->region->calls);
|
||||||
|
$this->assertCount(9, $this->region->calls['put']);
|
||||||
|
|
||||||
|
$this->assertInstanceOf('Doctrine\ORM\Cache\EntityCacheKey', $this->region->calls['put'][0]['key']);
|
||||||
|
$this->assertInstanceOf('Doctrine\ORM\Cache\EntityCacheKey', $this->region->calls['put'][1]['key']);
|
||||||
|
$this->assertInstanceOf('Doctrine\ORM\Cache\EntityCacheKey', $this->region->calls['put'][2]['key']);
|
||||||
|
$this->assertInstanceOf('Doctrine\ORM\Cache\EntityCacheKey', $this->region->calls['put'][3]['key']);
|
||||||
|
$this->assertInstanceOf('Doctrine\ORM\Cache\EntityCacheKey', $this->region->calls['put'][4]['key']);
|
||||||
|
$this->assertInstanceOf('Doctrine\ORM\Cache\EntityCacheKey', $this->region->calls['put'][5]['key']);
|
||||||
|
$this->assertInstanceOf('Doctrine\ORM\Cache\EntityCacheKey', $this->region->calls['put'][6]['key']);
|
||||||
|
$this->assertInstanceOf('Doctrine\ORM\Cache\EntityCacheKey', $this->region->calls['put'][7]['key']);
|
||||||
|
$this->assertInstanceOf('Doctrine\ORM\Cache\QueryCacheKey', $this->region->calls['put'][8]['key']);
|
||||||
|
}
|
||||||
|
|
||||||
public function testPutToOneAssociationNullQueryResult()
|
public function testPutToOneAssociationNullQueryResult()
|
||||||
{
|
{
|
||||||
$result = array();
|
$result = array();
|
||||||
@ -546,4 +591,4 @@ class CacheFactoryDefaultQueryCacheTest extends \Doctrine\ORM\Cache\DefaultCache
|
|||||||
{
|
{
|
||||||
return new \Doctrine\Tests\Mocks\TimestampRegionMock();
|
return new \Doctrine\Tests\Mocks\TimestampRegionMock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user