Fix non initialized association proxy
This commit is contained in:
parent
f0546455d5
commit
22e3a76327
@ -73,10 +73,7 @@ class DefaultEntityHydrator implements EntityHydrator
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( ! isset($assoc['cache']) ||
|
||||
($assoc['type'] & ClassMetadata::TO_ONE) === 0 ||
|
||||
($data[$name] instanceof Proxy && ! $data[$name]->__isInitialized__)) {
|
||||
|
||||
if ( ! isset($assoc['cache']) || ! ($assoc['type'] & ClassMetadata::TO_ONE)) {
|
||||
unset($data[$name]);
|
||||
|
||||
continue;
|
||||
|
@ -122,4 +122,32 @@ class DefaultEntityHydratorTest extends OrmTestCase
|
||||
'country' => array ('id' => 11),
|
||||
), $cache->data);
|
||||
}
|
||||
|
||||
public function testBuildCacheEntryNonInitializedAssocProxy()
|
||||
{
|
||||
$proxy = $this->em->getReference(Country::CLASSNAME, 11);
|
||||
$entity = new State('Bat', $proxy);
|
||||
$uow = $this->em->getUnitOfWork();
|
||||
$entityData = array('id'=>12, 'name'=>'Bar', 'country' => $proxy);
|
||||
$metadata = $this->em->getClassMetadata(State::CLASSNAME);
|
||||
$key = new EntityCacheKey($metadata->name, array('id'=>11));
|
||||
|
||||
$entity->setId(12);
|
||||
|
||||
$uow->registerManaged($entity, array('id'=>12), $entityData);
|
||||
|
||||
$cache = $this->structure->buildCacheEntry($metadata, $key, $entity);
|
||||
|
||||
$this->assertInstanceOf('Doctrine\ORM\Cache\CacheEntry', $cache);
|
||||
$this->assertInstanceOf('Doctrine\ORM\Cache\EntityCacheEntry', $cache);
|
||||
|
||||
$this->assertArrayHasKey('id', $cache->data);
|
||||
$this->assertArrayHasKey('name', $cache->data);
|
||||
$this->assertArrayHasKey('country', $cache->data);
|
||||
$this->assertEquals(array(
|
||||
'id' => 11,
|
||||
'name' => 'Bar',
|
||||
'country' => array ('id' => 11),
|
||||
), $cache->data);
|
||||
}
|
||||
}
|
@ -87,6 +87,8 @@ class SecondLevelCacheConcurrentTest extends SecondLevelCacheAbstractTest
|
||||
$state = $this->_em->find(State::CLASSNAME, $stateId);
|
||||
|
||||
$this->assertInstanceOf(State::CLASSNAME, $state);
|
||||
$this->assertInstanceOf(Country::CLASSNAME, $state->getCountry());
|
||||
$this->assertNotNull($state->getCountry()->getName());
|
||||
$this->assertCount(2, $state->getCities());
|
||||
|
||||
$this->_em->clear();
|
||||
|
@ -46,7 +46,10 @@ class SecondLevelCacheManyToManyTest extends SecondLevelCacheAbstractTest
|
||||
$this->loadFixturesTravels();
|
||||
|
||||
$this->_em->clear();
|
||||
$this->evictRegions();
|
||||
$this->cache->evictEntityRegion(City::CLASSNAME);
|
||||
$this->cache->evictEntityRegion(Travel::CLASSNAME);
|
||||
$this->cache->evictCollectionRegion(Travel::CLASSNAME, 'visitedCities');
|
||||
|
||||
$this->secondLevelCacheLogger->clearStats();
|
||||
|
||||
$this->assertFalse($this->cache->containsEntity(Travel::CLASSNAME, $this->travels[0]->getId()));
|
||||
|
@ -187,7 +187,10 @@ class SecondLevelCacheOneToManyTest extends SecondLevelCacheAbstractTest
|
||||
$this->loadFixturesCities();
|
||||
$this->_em->clear();
|
||||
$this->secondLevelCacheLogger->clearStats();
|
||||
$this->evictRegions();
|
||||
|
||||
$this->cache->evictEntityRegion(State::CLASSNAME);
|
||||
$this->cache->evictEntityRegion(City::CLASSNAME);
|
||||
$this->cache->evictCollectionRegion(State::CLASSNAME, 'cities');
|
||||
|
||||
$this->assertFalse($this->cache->containsEntity(State::CLASSNAME, $this->states[0]->getId()));
|
||||
$this->assertFalse($this->cache->containsCollection(State::CLASSNAME, 'cities', $this->states[0]->getId()));
|
||||
@ -288,7 +291,9 @@ class SecondLevelCacheOneToManyTest extends SecondLevelCacheAbstractTest
|
||||
$this->loadFixturesCities();
|
||||
|
||||
$this->secondLevelCacheLogger->clearStats();
|
||||
$this->evictRegions();
|
||||
$this->cache->evictEntityRegion(City::CLASSNAME);
|
||||
$this->cache->evictEntityRegion(State::CLASSNAME);
|
||||
$this->cache->evictCollectionRegion(State::CLASSNAME, 'cities');
|
||||
$this->_em->clear();
|
||||
|
||||
$entitiId = $this->states[0]->getId();
|
||||
|
@ -171,7 +171,11 @@ class SecondLevelCacheSingleTableInheritanceTest extends SecondLevelCacheAbstrac
|
||||
$this->loadFixturesStates();
|
||||
$this->loadFixturesCities();
|
||||
$this->loadFixturesAttractions();
|
||||
$this->evictRegions();
|
||||
|
||||
$this->cache->evictEntityRegion(City::CLASSNAME);
|
||||
$this->cache->evictEntityRegion(Attraction::CLASSNAME);
|
||||
$this->cache->evictCollectionRegion(City::CLASSNAME, 'attractions');
|
||||
|
||||
$this->_em->clear();
|
||||
|
||||
$entity = $this->_em->find(City::CLASSNAME, $this->cities[0]->getId());
|
||||
|
190
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2862Test.php
Normal file
190
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2862Test.php
Normal file
@ -0,0 +1,190 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\ORM\Functional\Ticket;
|
||||
|
||||
/**
|
||||
* @group DDC-2862
|
||||
*/
|
||||
class DDC2862Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
{
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->enableSecondLevelCache();
|
||||
parent::setUp();
|
||||
|
||||
$this->_schemaTool->createSchema(array(
|
||||
$this->_em->getClassMetadata(DDC2862User::CLASSNAME),
|
||||
$this->_em->getClassMetadata(DDC2862Driver::CLASSNAME),
|
||||
));
|
||||
}
|
||||
|
||||
public function testIssue()
|
||||
{
|
||||
$user1 = new DDC2862User('Foo');
|
||||
$driver1 = new DDC2862Driver('Bar' , $user1);
|
||||
|
||||
$this->_em->persist($user1);
|
||||
$this->_em->persist($driver1);
|
||||
$this->_em->flush();
|
||||
$this->_em->clear();
|
||||
|
||||
$this->assertTrue($this->_em->getCache()->containsEntity(DDC2862User::CLASSNAME, array('id' => $user1->getId())));
|
||||
$this->assertTrue($this->_em->getCache()->containsEntity(DDC2862Driver::CLASSNAME, array('id' => $driver1->getId())));
|
||||
|
||||
$queryCount = $this->getCurrentQueryCount();
|
||||
$driver2 = $this->_em->find(DDC2862Driver::CLASSNAME, $driver1->getId());
|
||||
|
||||
$this->assertEquals($queryCount, $this->getCurrentQueryCount());
|
||||
$this->assertInstanceOf(DDC2862Driver::CLASSNAME, $driver2);
|
||||
$this->assertInstanceOf(DDC2862User::CLASSNAME, $driver2->getUserProfile());
|
||||
|
||||
$driver2->setName('Franta');
|
||||
|
||||
$this->_em->flush();
|
||||
$this->_em->clear();
|
||||
|
||||
$this->assertTrue($this->_em->getCache()->containsEntity(DDC2862User::CLASSNAME, array('id' => $user1->getId())));
|
||||
$this->assertTrue($this->_em->getCache()->containsEntity(DDC2862Driver::CLASSNAME, array('id' => $driver1->getId())));
|
||||
|
||||
$queryCount = $this->getCurrentQueryCount();
|
||||
$driver3 = $this->_em->find(DDC2862Driver::CLASSNAME, $driver1->getId());
|
||||
|
||||
$this->assertEquals($queryCount, $this->getCurrentQueryCount());
|
||||
$this->assertInstanceOf(DDC2862Driver::CLASSNAME, $driver3);
|
||||
$this->assertInstanceOf(DDC2862User::CLASSNAME, $driver3->getUserProfile());
|
||||
$this->assertEquals('Franta', $driver3->getName());
|
||||
$this->assertEquals('Foo', $driver3->getUserProfile()->getName());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
* @Table(name="ddc2862_drivers")
|
||||
* @Cache("NONSTRICT_READ_WRITE")
|
||||
*/
|
||||
class DDC2862Driver
|
||||
{
|
||||
const CLASSNAME = __CLASS__;
|
||||
|
||||
/**
|
||||
* @Id
|
||||
* @GeneratedValue
|
||||
* @Column(type="integer")
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
* @Column(type="string")
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* @Cache()
|
||||
* @OneToOne(targetEntity="DDC2862User")
|
||||
* @var User
|
||||
*/
|
||||
protected $userProfile;
|
||||
|
||||
public function __construct($name, $userProfile = null)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->userProfile = $userProfile;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return integer
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
*/
|
||||
public function setName($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Entities\User $userProfile
|
||||
*/
|
||||
public function setUserProfile($userProfile)
|
||||
{
|
||||
$this->userProfile = $userProfile;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Entities\User
|
||||
*/
|
||||
public function getUserProfile()
|
||||
{
|
||||
return $this->userProfile;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
* @Table(name="ddc2862_users")
|
||||
* @Cache("NONSTRICT_READ_WRITE")
|
||||
*/
|
||||
class DDC2862User
|
||||
{
|
||||
const CLASSNAME = __CLASS__;
|
||||
|
||||
/**
|
||||
* @Id
|
||||
* @GeneratedValue
|
||||
* @Column(type="integer")
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
* @Column(type="string")
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
public function __construct($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return integer
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
*/
|
||||
public function setName($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user