3 namespace Doctrine\Tests\ORM\Functional\Ticket;
5 require_once __DIR__ . '/../../../TestInit.php';
7 class DDC531Test extends \Doctrine\Tests\OrmFunctionalTestCase
9 protected function setUp()
12 $this->_schemaTool->createSchema(array(
13 $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC531Item'),
14 $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC531SubItem'),
18 public function testIssue()
20 $item1 = new DDC531Item;
21 $item2 = new DDC531Item;
22 $item2->parent = $item1;
23 $item1->getChildren()->add($item2);
24 $this->_em->persist($item1);
25 $this->_em->persist($item2);
29 $item3 = $this->_em->find(__NAMESPACE__ . '\DDC531Item', $item2->id); // Load child item first (id 2)
30 // parent will already be loaded, cannot be lazy because it has mapped subclasses and we would not
31 // know which proxy type to put in.
32 $this->assertInstanceOf(__NAMESPACE__ . '\DDC531Item', $item3->parent);
33 $this->assertNotInstanceOf('Doctrine\ORM\Proxy\Proxy', $item3->parent);
34 $item4 = $this->_em->find(__NAMESPACE__ . '\DDC531Item', $item1->id); // Load parent item (id 1)
35 $this->assertNull($item4->parent);
36 $this->assertNotNull($item4->getChildren());
37 $this->assertTrue($item4->getChildren()->contains($item3)); // lazy-loads children
43 * @InheritanceType("SINGLE_TABLE")
44 * @DiscriminatorColumn(name="type", type="integer")
45 * @DiscriminatorMap({"0" = "DDC531Item", "1" = "DDC531SubItem"})
51 * @Column(type="integer")
52 * @GeneratedValue(strategy="AUTO")
57 * @OneToMany(targetEntity="DDC531Item", mappedBy="parent")
62 * @ManyToOne(targetEntity="DDC531Item", inversedBy="children")
63 * @JoinColumn(name="parentId", referencedColumnName="id")
67 public function __construct()
69 $this->children = new \Doctrine\Common\Collections\ArrayCollection;
72 public function getParent()
77 public function getChildren()
79 return $this->children;
86 class DDC531SubItem extends DDC531Item