-
-
Save doctrinebot/1594974b9f850635cc3b to your computer and use it in GitHub Desktop.
Attachments to Doctrine Jira Issue DDC-1452 - https://github.com/doctrine/doctrine2/issues/2080
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Doctrine\Tests\ORM\Functional\Ticket; | |
use Doctrine\ORM\UnitOfWork; | |
require_once __DIR__ . '/../../../TestInit.php'; | |
/** | |
* @group DDC-1452 | |
*/ | |
class DDC1452Test extends \Doctrine\Tests\OrmFunctionalTestCase | |
{ | |
protected function setUp() | |
{ | |
parent::setUp(); | |
try { | |
$this->_schemaTool->createSchema(array( | |
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1452EntityA'), | |
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1452EntityB'), | |
)); | |
} catch (\Exception $ignored) { | |
} | |
} | |
public function testIssue() | |
{ | |
$a = new DDC1452EntityA(); | |
$a->title = "foo"; | |
$b = new DDC1452EntityB(); | |
$b->entityAFrom = $a; | |
$b->entityATo = $a; | |
$this->_em->persist($a); | |
$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)->getResult(); | |
$this->assertSame($results[0], $results[0]->entitiesB[0]->entityAFrom); | |
$this->assertSame($results[0], $results[0]->entitiesB[0]->entityATo); | |
} | |
} | |
/** | |
* @Entity | |
*/ | |
class DDC1452EntityA | |
{ | |
/** @Id @Column(type="integer") @GeneratedValue */ | |
public $id; | |
/** @Column */ | |
public $title; | |
/** @ManyToMany(targetEntity="DDC1452EntityB", mappedBy="entityAFrom") */ | |
public $entitiesB; | |
} | |
/** | |
* @Entity | |
*/ | |
class DDC1452EntityB | |
{ | |
/** @Id @Column(type="integer") @GeneratedValue */ | |
public $id; | |
/** | |
* @ManyToOne(targetEntity="DDC1452EntityA", inversedBy="entitiesB") | |
*/ | |
public $entityAFrom; | |
/** | |
* @ManyToOne(targetEntity="DDC1452EntityA") | |
*/ | |
public $entityATo; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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() | |
{ | |
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->assertInstanceOf('Doctrine\Common\Collections\Collection', $results[0]->entitiesB[0]->entityATo->entitiesB); | |
} | |
} | |
/** | |
* @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(); | |
} | |
} | |
/** | |
* @Entity | |
*/ | |
class DDC1452EntityB | |
{ | |
/** @Id @Column(type="integer") @GeneratedValue */ | |
public $id; | |
/** | |
* @ManyToOne(targetEntity="DDC1452EntityA", inversedBy="entitiesB") | |
*/ | |
public $entityAFrom; | |
/** | |
* @ManyToOne(targetEntity="DDC1452EntityA") | |
*/ | |
public $entityATo; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment