Merge branch 'DDC-1452'
This commit is contained in:
commit
3e95eed76e
@ -94,13 +94,7 @@ class ObjectHydrator extends AbstractHydrator
|
||||
$sourceClass = $this->_getClassMetadata($sourceClassName);
|
||||
$assoc = $sourceClass->associationMappings[$this->_rsm->relationMap[$dqlAlias]];
|
||||
|
||||
$this->_hints['fetched'][$sourceClassName][$assoc['fieldName']] = true;
|
||||
|
||||
if ($sourceClass->subClasses) {
|
||||
foreach ($sourceClass->subClasses as $sourceSubclassName) {
|
||||
$this->_hints['fetched'][$sourceSubclassName][$assoc['fieldName']] = true;
|
||||
}
|
||||
}
|
||||
$this->_hints['fetched'][$this->_rsm->parentAliasMap[$dqlAlias]][$assoc['fieldName']] = true;
|
||||
|
||||
if ($assoc['type'] === ClassMetadata::MANY_TO_MANY) {
|
||||
continue;
|
||||
@ -108,11 +102,12 @@ class ObjectHydrator extends AbstractHydrator
|
||||
|
||||
// Mark any non-collection opposite sides as fetched, too.
|
||||
if ($assoc['mappedBy']) {
|
||||
$this->_hints['fetched'][$className][$assoc['mappedBy']] = true;
|
||||
$this->_hints['fetched'][$dqlAlias][$assoc['mappedBy']] = true;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// handle fetch-joined owning side bi-directional one-to-one associations
|
||||
if ($assoc['inversedBy']) {
|
||||
$class = $this->_ce[$className];
|
||||
$inverseAssoc = $class->associationMappings[$assoc['inversedBy']];
|
||||
@ -121,13 +116,7 @@ class ObjectHydrator extends AbstractHydrator
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->_hints['fetched'][$className][$inverseAssoc['fieldName']] = true;
|
||||
|
||||
if ($class->subClasses) {
|
||||
foreach ($class->subClasses as $targetSubclassName) {
|
||||
$this->_hints['fetched'][$targetSubclassName][$inverseAssoc['fieldName']] = true;
|
||||
}
|
||||
}
|
||||
$this->_hints['fetched'][$dqlAlias][$inverseAssoc['fieldName']] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -175,9 +164,11 @@ class ObjectHydrator extends AbstractHydrator
|
||||
* Initializes a related collection.
|
||||
*
|
||||
* @param object $entity The entity to which the collection belongs.
|
||||
* @param ClassMetadata $class
|
||||
* @param string $name The name of the field on the entity that holds the collection.
|
||||
* @param string $parentDqlAlias Alias of the parent fetch joining this collection.
|
||||
*/
|
||||
private function _initRelatedCollection($entity, $class, $fieldName)
|
||||
private function _initRelatedCollection($entity, $class, $fieldName, $parentDqlAlias)
|
||||
{
|
||||
$oid = spl_object_hash($entity);
|
||||
$relation = $class->associationMappings[$fieldName];
|
||||
@ -199,7 +190,7 @@ class ObjectHydrator extends AbstractHydrator
|
||||
$this->_initializedCollections[$oid . $fieldName] = $value;
|
||||
} else if (
|
||||
isset($this->_hints[Query::HINT_REFRESH]) ||
|
||||
isset($this->_hints['fetched'][$class->name][$fieldName]) &&
|
||||
isset($this->_hints['fetched'][$parentDqlAlias][$fieldName]) &&
|
||||
! $value->isInitialized()
|
||||
) {
|
||||
// Is already PersistentCollection, but either REFRESH or FETCH-JOIN and UNINITIALIZED!
|
||||
@ -243,6 +234,7 @@ class ObjectHydrator extends AbstractHydrator
|
||||
$this->registerManaged($this->_ce[$className], $this->_hints[Query::HINT_REFRESH_ENTITY], $data);
|
||||
}
|
||||
|
||||
$this->_hints['fetchAlias'] = $dqlAlias;
|
||||
return $this->_uow->createEntity($className, $data, $this->_hints);
|
||||
}
|
||||
|
||||
@ -367,7 +359,7 @@ class ObjectHydrator extends AbstractHydrator
|
||||
if (isset($this->_initializedCollections[$collKey])) {
|
||||
$reflFieldValue = $this->_initializedCollections[$collKey];
|
||||
} else if ( ! isset($this->_existingCollections[$collKey])) {
|
||||
$reflFieldValue = $this->_initRelatedCollection($parentObject, $parentClass, $relationField);
|
||||
$reflFieldValue = $this->_initRelatedCollection($parentObject, $parentClass, $relationField, $parentAlias);
|
||||
}
|
||||
|
||||
$indexExists = isset($this->_identifierMap[$path][$id[$parentAlias]][$id[$dqlAlias]]);
|
||||
@ -402,7 +394,7 @@ class ObjectHydrator extends AbstractHydrator
|
||||
$this->_resultPointers[$dqlAlias] = $reflFieldValue[$index];
|
||||
}
|
||||
} else if ( ! $reflField->getValue($parentObject)) {
|
||||
$reflFieldValue = $this->_initRelatedCollection($parentObject, $parentClass, $relationField);
|
||||
$reflFieldValue = $this->_initRelatedCollection($parentObject, $parentClass, $relationField, $parentAlias);
|
||||
}
|
||||
} else {
|
||||
// PATH B: Single-valued association
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -49,17 +49,21 @@ class DDC1335Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
$this->assertEquals(sizeof($result['bar@bar.com']->phones), 3);
|
||||
$this->assertEquals(sizeof($result['foobar@foobar.com']->phones), 3);
|
||||
|
||||
$this->assertArrayHasKey(1, $result['foo@foo.com']->phones->toArray());
|
||||
$this->assertArrayHasKey(2, $result['foo@foo.com']->phones->toArray());
|
||||
$this->assertArrayHasKey(3, $result['foo@foo.com']->phones->toArray());
|
||||
$foo = $result['foo@foo.com']->phones->toArray();
|
||||
$bar = $result['bar@bar.com']->phones->toArray();
|
||||
$foobar = $result['foobar@foobar.com']->phones->toArray();
|
||||
|
||||
$this->assertArrayHasKey(4, $result['bar@bar.com']->phones->toArray());
|
||||
$this->assertArrayHasKey(5, $result['bar@bar.com']->phones->toArray());
|
||||
$this->assertArrayHasKey(6, $result['bar@bar.com']->phones->toArray());
|
||||
$this->assertArrayHasKey(1, $foo);
|
||||
$this->assertArrayHasKey(2, $foo);
|
||||
$this->assertArrayHasKey(3, $foo);
|
||||
|
||||
$this->assertArrayHasKey(7, $result['foobar@foobar.com']->phones->toArray());
|
||||
$this->assertArrayHasKey(8, $result['foobar@foobar.com']->phones->toArray());
|
||||
$this->assertArrayHasKey(9, $result['foobar@foobar.com']->phones->toArray());
|
||||
$this->assertArrayHasKey(4, $bar);
|
||||
$this->assertArrayHasKey(5, $bar);
|
||||
$this->assertArrayHasKey(6, $bar);
|
||||
|
||||
$this->assertArrayHasKey(7, $foobar);
|
||||
$this->assertArrayHasKey(8, $foobar);
|
||||
$this->assertArrayHasKey(9, $foobar);
|
||||
}
|
||||
|
||||
public function testTicket()
|
||||
|
127
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1452Test.php
Normal file
127
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1452Test.php
Normal file
@ -0,0 +1,127 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\ORM\Functional\Ticket;
|
||||
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\ORM\UnitOfWork;
|
||||
|
||||
require_once __DIR__ . '/../../../TestInit.php';
|
||||
|
||||
/**
|
||||
* @group DDC-1452
|
||||
*/
|
||||
class DDC1452Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
$this->useModelSet('cms');
|
||||
parent::setUp();
|
||||
|
||||
try {
|
||||
$this->_schemaTool->createSchema(array(
|
||||
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1452EntityA'),
|
||||
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1452EntityB'),
|
||||
));
|
||||
} catch (\Exception $ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
public function testIssue()
|
||||
{
|
||||
$a1 = new DDC1452EntityA();
|
||||
$a1->title = "foo";
|
||||
|
||||
$a2 = new DDC1452EntityA();
|
||||
$a2->title = "bar";
|
||||
|
||||
$b = new DDC1452EntityB();
|
||||
$b->entityAFrom = $a1;
|
||||
$b->entityATo = $a2;
|
||||
|
||||
$this->_em->persist($a1);
|
||||
$this->_em->persist($a2);
|
||||
$this->_em->persist($b);
|
||||
$this->_em->flush();
|
||||
$this->_em->clear();
|
||||
|
||||
$dql = "SELECT a, b, ba FROM " . __NAMESPACE__ . "\DDC1452EntityA AS a LEFT JOIN a.entitiesB AS b LEFT JOIN b.entityATo AS ba";
|
||||
$results = $this->_em->createQuery($dql)->setMaxResults(1)->getResult();
|
||||
|
||||
$this->assertSame($results[0], $results[0]->entitiesB[0]->entityAFrom);
|
||||
$this->assertFalse( $results[0]->entitiesB[0]->entityATo instanceof \Doctrine\ORM\Proxy\Proxy );
|
||||
$this->assertInstanceOf('Doctrine\Common\Collections\Collection', $results[0]->entitiesB[0]->entityATo->getEntitiesB());
|
||||
}
|
||||
|
||||
public function testFetchJoinOneToOneFromInverse()
|
||||
{
|
||||
$address = new \Doctrine\Tests\Models\CMS\CmsAddress();
|
||||
$address->city = "Bonn";
|
||||
$address->country = "Germany";
|
||||
$address->street = "Somestreet";
|
||||
$address->zip = 12345;
|
||||
|
||||
$user = new \Doctrine\Tests\Models\CMS\CmsUser();
|
||||
$user->name = "beberlei";
|
||||
$user->username = "beberlei";
|
||||
$user->status = "active";
|
||||
$user->address = $address;
|
||||
$address->user = $user;
|
||||
|
||||
$this->_em->persist($address);
|
||||
$this->_em->persist($user);
|
||||
$this->_em->flush();
|
||||
$this->_em->clear();
|
||||
|
||||
$dql = "SELECT a, u FROM Doctrine\Tests\Models\CMS\CmsAddress a INNER JOIN a.user u";
|
||||
$data = $this->_em->createQuery($dql)->getResult();
|
||||
$this->_em->clear();
|
||||
|
||||
$this->assertFalse($data[0]->user instanceof \Doctrine\ORM\Proxy\Proxy);
|
||||
|
||||
$dql = "SELECT u, a FROM Doctrine\Tests\Models\CMS\CmsUser u INNER JOIN u.address a";
|
||||
$data = $this->_em->createQuery($dql)->getResult();
|
||||
|
||||
$this->assertFalse($data[0]->address instanceof \Doctrine\ORM\Proxy\Proxy);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
*/
|
||||
class DDC1452EntityA
|
||||
{
|
||||
/** @Id @Column(type="integer") @GeneratedValue */
|
||||
public $id;
|
||||
/** @Column */
|
||||
public $title;
|
||||
/** @ManyToMany(targetEntity="DDC1452EntityB", mappedBy="entityAFrom") */
|
||||
public $entitiesB;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->entitiesB = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function getEntitiesB()
|
||||
{
|
||||
return $this->entitiesB;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
*/
|
||||
class DDC1452EntityB
|
||||
{
|
||||
/** @Id @Column(type="integer") @GeneratedValue */
|
||||
public $id;
|
||||
|
||||
/**
|
||||
* @ManyToOne(targetEntity="DDC1452EntityA", inversedBy="entitiesB")
|
||||
*/
|
||||
public $entityAFrom;
|
||||
/**
|
||||
* @ManyToOne(targetEntity="DDC1452EntityA")
|
||||
*/
|
||||
public $entityATo;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user