Commit 71c1fe52 authored by romanb's avatar romanb

[2.0][DDC-2] Fixed.

parent bda1b9ae
...@@ -49,6 +49,7 @@ class ObjectHydrator extends AbstractHydrator ...@@ -49,6 +49,7 @@ class ObjectHydrator extends AbstractHydrator
private $_fetchedAssociations; private $_fetchedAssociations;
private $_rootAliases = array(); private $_rootAliases = array();
private $_initializedCollections = array(); private $_initializedCollections = array();
private $_proxyFactory;
/** @override */ /** @override */
protected function _prepare() protected function _prepare()
...@@ -56,6 +57,10 @@ class ObjectHydrator extends AbstractHydrator ...@@ -56,6 +57,10 @@ class ObjectHydrator extends AbstractHydrator
$this->_allowPartialObjects = $this->_em->getConfiguration()->getAllowPartialObjects() $this->_allowPartialObjects = $this->_em->getConfiguration()->getAllowPartialObjects()
|| isset($this->_hints[Query::HINT_FORCE_PARTIAL_LOAD]); || isset($this->_hints[Query::HINT_FORCE_PARTIAL_LOAD]);
if ( ! $this->_allowPartialObjects) {
$this->_proxyFactory = $this->_em->getProxyFactory();
}
$this->_identifierMap = $this->_identifierMap =
$this->_resultPointers = $this->_resultPointers =
$this->_idTemplate = $this->_idTemplate =
...@@ -184,6 +189,7 @@ class ObjectHydrator extends AbstractHydrator ...@@ -184,6 +189,7 @@ class ObjectHydrator extends AbstractHydrator
// Properly initialize any unfetched associations, if partial objects are not allowed. // Properly initialize any unfetched associations, if partial objects are not allowed.
if ( ! $this->_allowPartialObjects) { if ( ! $this->_allowPartialObjects) {
$oid = spl_object_hash($entity);
foreach ($this->_getClassMetadata($className)->associationMappings as $field => $assoc) { foreach ($this->_getClassMetadata($className)->associationMappings as $field => $assoc) {
// Check if the association is not among the fetch-joined associatons already. // Check if the association is not among the fetch-joined associatons already.
if ( ! isset($this->_fetchedAssociations[$className][$field])) { if ( ! isset($this->_fetchedAssociations[$className][$field])) {
...@@ -194,9 +200,9 @@ class ObjectHydrator extends AbstractHydrator ...@@ -194,9 +200,9 @@ class ObjectHydrator extends AbstractHydrator
} }
if ($assoc->isLazilyFetched()) { if ($assoc->isLazilyFetched()) {
// Inject proxy // Inject proxy
$this->_ce[$className]->reflFields[$field]->setValue($entity, $proxy = $this->_proxyFactory->getAssociationProxy($entity, $assoc, $joinColumns);
$this->_em->getProxyFactory()->getAssociationProxy($entity, $assoc, $joinColumns) $this->_uow->setOriginalEntityProperty($oid, $field, $proxy);
); $this->_ce[$className]->reflFields[$field]->setValue($entity, $proxy);
} else { } else {
// Eager load // Eager load
//TODO: Allow more efficient and configurable batching of these loads //TODO: Allow more efficient and configurable batching of these loads
...@@ -217,6 +223,7 @@ class ObjectHydrator extends AbstractHydrator ...@@ -217,6 +223,7 @@ class ObjectHydrator extends AbstractHydrator
//TODO: Allow more efficient and configurable batching of these loads //TODO: Allow more efficient and configurable batching of these loads
$assoc->load($entity, $pColl, $this->_em); $assoc->load($entity, $pColl, $this->_em);
} }
$this->_uow->setOriginalEntityProperty($oid, $field, $pColl);
} }
} }
} }
......
...@@ -598,6 +598,9 @@ class UnitOfWork implements PropertyChangedListener ...@@ -598,6 +598,9 @@ class UnitOfWork implements PropertyChangedListener
* Computes the changeset of an individual entity, independently of the * Computes the changeset of an individual entity, independently of the
* computeChangeSets() routine that is used at the beginning of a UnitOfWork#commit(). * computeChangeSets() routine that is used at the beginning of a UnitOfWork#commit().
* *
* The passed entity must be a managed entity.
*
* @ignore
* @param $class * @param $class
* @param $entity * @param $entity
*/ */
...@@ -1381,7 +1384,7 @@ class UnitOfWork implements PropertyChangedListener ...@@ -1381,7 +1384,7 @@ class UnitOfWork implements PropertyChangedListener
$this->removeFromIdentityMap($entity); $this->removeFromIdentityMap($entity);
unset($this->_entityInsertions[$oid], $this->_entityUpdates[$oid], unset($this->_entityInsertions[$oid], $this->_entityUpdates[$oid],
$this->_entityDeletions[$oid], $this->_entityIdentifiers[$oid], $this->_entityDeletions[$oid], $this->_entityIdentifiers[$oid],
$this->_entityStates[$oid]); $this->_entityStates[$oid], $this->_originalEntityData[$oid]);
break; break;
case self::STATE_NEW: case self::STATE_NEW:
case self::STATE_DETACHED: case self::STATE_DETACHED:
......
...@@ -79,7 +79,8 @@ class OneToOneBidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctional ...@@ -79,7 +79,8 @@ class OneToOneBidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctional
$this->assertEquals('Giorgio', $cart->getCustomer()->getName()); $this->assertEquals('Giorgio', $cart->getCustomer()->getName());
} }
public function testLazyLoadsObjectsOnTheInverseSide() { public function testLazyLoadsObjectsOnTheInverseSide()
{
$this->_createFixture(); $this->_createFixture();
$this->_em->getConfiguration()->setAllowPartialObjects(false); $this->_em->getConfiguration()->setAllowPartialObjects(false);
$metadata = $this->_em->getClassMetadata('Doctrine\Tests\Models\ECommerce\ECommerceCustomer'); $metadata = $this->_em->getClassMetadata('Doctrine\Tests\Models\ECommerce\ECommerceCustomer');
...@@ -93,6 +94,45 @@ class OneToOneBidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctional ...@@ -93,6 +94,45 @@ class OneToOneBidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctional
$this->assertTrue($customer->getCart() instanceof ECommerceCart); $this->assertTrue($customer->getCart() instanceof ECommerceCart);
$this->assertEquals('paypal', $customer->getCart()->getPayment()); $this->assertEquals('paypal', $customer->getCart()->getPayment());
} }
public function testUpdateWithProxyObject()
{
$this->_em->getConfiguration()->setAllowPartialObjects(false);
$cust = new ECommerceCustomer;
$cust->setName('Roman');
$cart = new ECommerceCart;
$cart->setPayment('CARD');
$cust->setCart($cart);
$this->_em->persist($cust);
$this->_em->flush();
$this->_em->clear();
$this->assertTrue($cust->getCart() instanceof ECommerceCart);
$this->assertEquals('Roman', $cust->getName());
$this->assertSame($cust, $cart->getCustomer());
$query = $this->_em->createQuery('select ca from Doctrine\Tests\Models\ECommerce\ECommerceCart ca where ca.id =?1');
$query->setParameter(1, $cart->getId());
$cart2 = $query->getSingleResult();
$cart2->setPayment('CHEQUE');
$this->_em->flush();
$this->_em->clear();
$query2 = $this->_em->createQuery('select ca, c from Doctrine\Tests\Models\ECommerce\ECommerceCart ca left join ca.customer c where ca.id =?1');
$query2->setParameter(1, $cart->getId());
$cart3 = $query2->getSingleResult();
$this->assertTrue($cart3->getCustomer() instanceof ECommerceCustomer);
$this->assertEquals('Roman', $cart3->getCustomer()->getName());
$this->_em->getConfiguration()->setAllowPartialObjects(true);
}
protected function _createFixture() protected function _createFixture()
{ {
......
...@@ -162,6 +162,8 @@ class OrmFunctionalTestCase extends OrmTestCase ...@@ -162,6 +162,8 @@ class OrmFunctionalTestCase extends OrmTestCase
if (is_null(self::$_queryCacheImpl)) { if (is_null(self::$_queryCacheImpl)) {
self::$_queryCacheImpl = new \Doctrine\Common\Cache\ArrayCache; self::$_queryCacheImpl = new \Doctrine\Common\Cache\ArrayCache;
} }
//FIXME: two different configs! $conn and the created entity manager have
// different configs.
$config = new \Doctrine\ORM\Configuration(); $config = new \Doctrine\ORM\Configuration();
$config->setMetadataCacheImpl(self::$_metadataCacheImpl); $config->setMetadataCacheImpl(self::$_metadataCacheImpl);
$config->setQueryCacheImpl(self::$_queryCacheImpl); $config->setQueryCacheImpl(self::$_queryCacheImpl);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment