3 namespace Doctrine\Tests\ORM\Functional\Ticket;
5 use Doctrine\Common\Collections\ArrayCollection;
7 require_once __DIR__ . '/../../../TestInit.php';
12 class DDC992Test extends \Doctrine\Tests\OrmFunctionalTestCase
14 public function setUp()
18 $this->_schemaTool->createSchema(array(
19 $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC992Role'),
20 $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC992Parent'),
21 $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC992Child'),
23 } catch(\Exception $e) {
28 public function testIssue()
30 $role = new DDC992Role();
31 $role->name = "Parent";
32 $child = new DDC992Role();
33 $child->name = "child";
35 $role->extendedBy[] = $child;
36 $child->extends[] = $role;
38 $this->_em->persist($role);
39 $this->_em->persist($child);
43 $child = $this->_em->getRepository(get_class($role))->find($child->roleID);
44 $parents = count($child->extends);
45 $this->assertEquals(1, $parents);
46 foreach ($child->extends AS $parent) {
47 $this->assertEquals($role->getRoleID(), $parent->getRoleID());
51 public function testOneToManyChild()
53 $parent = new DDC992Parent();
54 $child = new DDC992Child();
55 $child->parent = $parent;
56 $parent->childs[] = $child;
58 $this->_em->persist($parent);
59 $this->_em->persist($child);
63 $parentRepository = $this->_em->getRepository(get_class($parent));
64 $childRepository = $this->_em->getRepository(get_class($child));
66 $parent = $parentRepository->find($parent->id);
67 $this->assertEquals(1, count($parent->childs));
68 $this->assertEquals(0, count($parent->childs[0]->childs()));
70 $child = $parentRepository->findOneBy(array("id" => $child->id));
71 $this->assertSame($parent->childs[0], $child);
75 $child = $parentRepository->find($child->id);
76 $this->assertEquals(0, count($child->childs));
80 $child = $childRepository->find($child->id);
81 $this->assertEquals(0, count($child->childs));
87 * @InheritanceType("JOINED")
88 * @DiscriminatorMap({"child" = "DDC992Child", "parent" = "DDC992Parent"})
92 /** @Id @GeneratedValue @Column(type="integer") */
94 /** @ManyToOne(targetEntity="DDC992Parent", inversedBy="childs") */
96 /** @OneToMany(targetEntity="DDC992Child", mappedBy="parent") */
103 class DDC992Child extends DDC992Parent
105 public function childs()
107 return $this->childs;
116 public function getRoleID()
118 return $this->roleID;
122 * @Id @Column(name="roleID", type="integer")
123 * @GeneratedValue(strategy="AUTO")
127 * @Column (name="name", type="string", length=45)
131 * @ManyToMany (targetEntity="DDC992Role", mappedBy="extends")
135 * @ManyToMany (targetEntity="DDC992Role", inversedBy="extendedBy")
136 * @JoinTable (name="RoleRelations",
137 * joinColumns={@JoinColumn(name="roleID", referencedColumnName="roleID")},
138 * inverseJoinColumns={@JoinColumn(name="extendsRoleID", referencedColumnName="roleID")}
143 public function __construct() {
144 $this->extends = new ArrayCollection;
145 $this->extendedBy = new ArrayCollection;