DDC1452Test.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. namespace Doctrine\Tests\ORM\Functional\Ticket;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\ORM\UnitOfWork;
  5. require_once __DIR__ . '/../../../TestInit.php';
  6. /**
  7. * @group DDC-1452
  8. */
  9. class DDC1452Test extends \Doctrine\Tests\OrmFunctionalTestCase
  10. {
  11. protected function setUp()
  12. {
  13. $this->useModelSet('cms');
  14. parent::setUp();
  15. try {
  16. $this->_schemaTool->createSchema(array(
  17. $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1452EntityA'),
  18. $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1452EntityB'),
  19. ));
  20. } catch (\Exception $ignored) {
  21. }
  22. }
  23. public function testIssue()
  24. {
  25. $a1 = new DDC1452EntityA();
  26. $a1->title = "foo";
  27. $a2 = new DDC1452EntityA();
  28. $a2->title = "bar";
  29. $b = new DDC1452EntityB();
  30. $b->entityAFrom = $a1;
  31. $b->entityATo = $a2;
  32. $this->_em->persist($a1);
  33. $this->_em->persist($a2);
  34. $this->_em->persist($b);
  35. $this->_em->flush();
  36. $this->_em->clear();
  37. $dql = "SELECT a, b, ba FROM " . __NAMESPACE__ . "\DDC1452EntityA AS a LEFT JOIN a.entitiesB AS b LEFT JOIN b.entityATo AS ba";
  38. $results = $this->_em->createQuery($dql)->setMaxResults(1)->getResult();
  39. $this->assertSame($results[0], $results[0]->entitiesB[0]->entityAFrom);
  40. $this->assertFalse( $results[0]->entitiesB[0]->entityATo instanceof \Doctrine\ORM\Proxy\Proxy );
  41. $this->assertInstanceOf('Doctrine\Common\Collections\Collection', $results[0]->entitiesB[0]->entityATo->getEntitiesB());
  42. }
  43. public function testFetchJoinOneToOneFromInverse()
  44. {
  45. $address = new \Doctrine\Tests\Models\CMS\CmsAddress();
  46. $address->city = "Bonn";
  47. $address->country = "Germany";
  48. $address->street = "Somestreet";
  49. $address->zip = 12345;
  50. $user = new \Doctrine\Tests\Models\CMS\CmsUser();
  51. $user->name = "beberlei";
  52. $user->username = "beberlei";
  53. $user->status = "active";
  54. $user->address = $address;
  55. $address->user = $user;
  56. $this->_em->persist($address);
  57. $this->_em->persist($user);
  58. $this->_em->flush();
  59. $this->_em->clear();
  60. $dql = "SELECT a, u FROM Doctrine\Tests\Models\CMS\CmsAddress a INNER JOIN a.user u";
  61. $data = $this->_em->createQuery($dql)->getResult();
  62. $this->_em->clear();
  63. $this->assertFalse($data[0]->user instanceof \Doctrine\ORM\Proxy\Proxy);
  64. $dql = "SELECT u, a FROM Doctrine\Tests\Models\CMS\CmsUser u INNER JOIN u.address a";
  65. $data = $this->_em->createQuery($dql)->getResult();
  66. $this->assertFalse($data[0]->address instanceof \Doctrine\ORM\Proxy\Proxy);
  67. }
  68. }
  69. /**
  70. * @Entity
  71. */
  72. class DDC1452EntityA
  73. {
  74. /** @Id @Column(type="integer") @GeneratedValue */
  75. public $id;
  76. /** @Column */
  77. public $title;
  78. /** @ManyToMany(targetEntity="DDC1452EntityB", mappedBy="entityAFrom") */
  79. public $entitiesB;
  80. public function __construct()
  81. {
  82. $this->entitiesB = new ArrayCollection();
  83. }
  84. public function getEntitiesB()
  85. {
  86. return $this->entitiesB;
  87. }
  88. }
  89. /**
  90. * @Entity
  91. */
  92. class DDC1452EntityB
  93. {
  94. /** @Id @Column(type="integer") @GeneratedValue */
  95. public $id;
  96. /**
  97. * @ManyToOne(targetEntity="DDC1452EntityA", inversedBy="entitiesB")
  98. */
  99. public $entityAFrom;
  100. /**
  101. * @ManyToOne(targetEntity="DDC1452EntityA")
  102. */
  103. public $entityATo;
  104. }