DDC371Test.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace Doctrine\Tests\ORM\Functional\Ticket;
  3. use Doctrine\ORM\Query;
  4. require_once __DIR__ . '/../../../TestInit.php';
  5. class DDC371Test extends \Doctrine\Tests\OrmFunctionalTestCase
  6. {
  7. protected function setUp()
  8. {
  9. parent::setUp();
  10. //$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger);
  11. $this->_schemaTool->createSchema(array(
  12. $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC371Parent'),
  13. $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC371Child')
  14. ));
  15. }
  16. public function testIssue()
  17. {
  18. $parent = new DDC371Parent;
  19. $parent->data = 'parent';
  20. $parent->children = new \Doctrine\Common\Collections\ArrayCollection;
  21. $child = new DDC371Child;
  22. $child->data = 'child';
  23. $child->parent = $parent;
  24. $parent->children->add($child);
  25. $this->_em->persist($parent);
  26. $this->_em->persist($child);
  27. $this->_em->flush();
  28. $this->_em->clear();
  29. $children = $this->_em->createQuery('select c,p from '.__NAMESPACE__.'\DDC371Child c '
  30. . 'left join c.parent p where c.id = 1 and p.id = 1')
  31. ->setHint(Query::HINT_REFRESH, true)
  32. ->getResult();
  33. $this->assertEquals(1, count($children));
  34. $this->assertNotInstanceOf('Doctrine\ORM\Proxy\Proxy', $children[0]->parent);
  35. $this->assertFalse($children[0]->parent->children->isInitialized());
  36. $this->assertEquals(0, $children[0]->parent->children->unwrap()->count());
  37. }
  38. }
  39. /** @Entity */
  40. class DDC371Child {
  41. /** @Id @Column(type="integer") @GeneratedValue */
  42. private $id;
  43. /** @Column(type="string") */
  44. public $data;
  45. /** @ManyToOne(targetEntity="DDC371Parent", inversedBy="children") @JoinColumn(name="parentId") */
  46. public $parent;
  47. }
  48. /** @Entity */
  49. class DDC371Parent {
  50. /** @Id @Column(type="integer") @GeneratedValue */
  51. private $id;
  52. /** @Column(type="string") */
  53. public $data;
  54. /** @OneToMany(targetEntity="DDC371Child", mappedBy="parent") */
  55. public $children;
  56. }