Commit 71c1fe52 authored by romanb's avatar romanb

[2.0][DDC-2] Fixed.

parent bda1b9ae
......@@ -49,6 +49,7 @@ class ObjectHydrator extends AbstractHydrator
private $_fetchedAssociations;
private $_rootAliases = array();
private $_initializedCollections = array();
private $_proxyFactory;
/** @override */
protected function _prepare()
......@@ -56,6 +57,10 @@ class ObjectHydrator extends AbstractHydrator
$this->_allowPartialObjects = $this->_em->getConfiguration()->getAllowPartialObjects()
|| isset($this->_hints[Query::HINT_FORCE_PARTIAL_LOAD]);
if ( ! $this->_allowPartialObjects) {
$this->_proxyFactory = $this->_em->getProxyFactory();
}
$this->_identifierMap =
$this->_resultPointers =
$this->_idTemplate =
......@@ -184,6 +189,7 @@ class ObjectHydrator extends AbstractHydrator
// Properly initialize any unfetched associations, if partial objects are not allowed.
if ( ! $this->_allowPartialObjects) {
$oid = spl_object_hash($entity);
foreach ($this->_getClassMetadata($className)->associationMappings as $field => $assoc) {
// Check if the association is not among the fetch-joined associatons already.
if ( ! isset($this->_fetchedAssociations[$className][$field])) {
......@@ -194,9 +200,9 @@ class ObjectHydrator extends AbstractHydrator
}
if ($assoc->isLazilyFetched()) {
// Inject proxy
$this->_ce[$className]->reflFields[$field]->setValue($entity,
$this->_em->getProxyFactory()->getAssociationProxy($entity, $assoc, $joinColumns)
);
$proxy = $this->_proxyFactory->getAssociationProxy($entity, $assoc, $joinColumns);
$this->_uow->setOriginalEntityProperty($oid, $field, $proxy);
$this->_ce[$className]->reflFields[$field]->setValue($entity, $proxy);
} else {
// Eager load
//TODO: Allow more efficient and configurable batching of these loads
......@@ -217,6 +223,7 @@ class ObjectHydrator extends AbstractHydrator
//TODO: Allow more efficient and configurable batching of these loads
$assoc->load($entity, $pColl, $this->_em);
}
$this->_uow->setOriginalEntityProperty($oid, $field, $pColl);
}
}
}
......
......@@ -598,6 +598,9 @@ class UnitOfWork implements PropertyChangedListener
* Computes the changeset of an individual entity, independently of the
* computeChangeSets() routine that is used at the beginning of a UnitOfWork#commit().
*
* The passed entity must be a managed entity.
*
* @ignore
* @param $class
* @param $entity
*/
......@@ -1381,7 +1384,7 @@ class UnitOfWork implements PropertyChangedListener
$this->removeFromIdentityMap($entity);
unset($this->_entityInsertions[$oid], $this->_entityUpdates[$oid],
$this->_entityDeletions[$oid], $this->_entityIdentifiers[$oid],
$this->_entityStates[$oid]);
$this->_entityStates[$oid], $this->_originalEntityData[$oid]);
break;
case self::STATE_NEW:
case self::STATE_DETACHED:
......
......@@ -79,7 +79,8 @@ class OneToOneBidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctional
$this->assertEquals('Giorgio', $cart->getCustomer()->getName());
}
public function testLazyLoadsObjectsOnTheInverseSide() {
public function testLazyLoadsObjectsOnTheInverseSide()
{
$this->_createFixture();
$this->_em->getConfiguration()->setAllowPartialObjects(false);
$metadata = $this->_em->getClassMetadata('Doctrine\Tests\Models\ECommerce\ECommerceCustomer');
......@@ -94,6 +95,45 @@ class OneToOneBidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctional
$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()
{
$customer = new ECommerceCustomer;
......
......@@ -162,6 +162,8 @@ class OrmFunctionalTestCase extends OrmTestCase
if (is_null(self::$_queryCacheImpl)) {
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->setMetadataCacheImpl(self::$_metadataCacheImpl);
$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