Skip to content

Instantly share code, notes, and snippets.

@doctrinebot
Created December 13, 2015 18:47
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save doctrinebot/45247193c4df2d1e03a2 to your computer and use it in GitHub Desktop.
Attachments to Doctrine Jira Issue DDC-531 - https://github.com/doctrine/doctrine2/issues/5041
<?php
namespace Doctrine\Tests\ORM\Functional\Ticket;
require_once __DIR__ . '/../../../TestInit.php';
class DDC531Test extends \Doctrine\Tests\OrmFunctionalTestCase
{
protected function setUp()
{
parent::setUp();
$this->_schemaTool->createSchema(array(
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC531Item'),
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC531SubItem'),
));
}
public function testIssue()
{
$item1 = new DDC531Item;
$item2 = new DDC531Item;
$item2->parent = $item1;
$item1->getChildren()->add($item2);
$this->_em->persist($item1);
$this->_em->persist($item2);
$this->_em->flush();
$this->_em->clear();
$item3 = $this->_em->find(__NAMESPACE__ . '\DDC531Item', $item2->id); // Load child item first (id 2)
$item4 = $this->_em->find(__NAMESPACE__ . '\DDC531Item', $item1->id); // Load parent item (id 1)
$this->assertNotEquals($item4->getChildren(), NULL);
$this->assertTrue($item4->getChildren()->contains($item3));
}
}
/**
* @Entity
* @InheritanceType("SINGLE_TABLE")
* @DiscriminatorColumn(name="type", type="integer")
* @DiscriminatorMap({"0" = "DDC531Item", "1" = "DDC531SubItem"})
*/
class DDC531Item
{
/**
* @Id
* @Column(type="integer")
* @GeneratedValue(strategy="AUTO")
*/
public $id;
/**
* @OneToMany(targetEntity="DDC531Item", mappedBy="parent")
*/
protected $children;
/**
* @ManyToOne(targetEntity="DDC531Item", inversedBy="children")
* @JoinColumn(name="parentId", referencedColumnName="id")
*/
public $parent;
public function __construct()
{
$this->children = new \Doctrine\Common\Collections\ArrayCollection;
}
public function getChildren()
{
return $this->children;
}
}
/**
* @Entity
*/
class DDC531SubItem extends DDC531Item
{
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment