Skip to content

Instantly share code, notes, and snippets.

@doctrinebot
Created December 13, 2015 18:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save doctrinebot/edd1d8dcc239343ca8d3 to your computer and use it in GitHub Desktop.
Save doctrinebot/edd1d8dcc239343ca8d3 to your computer and use it in GitHub Desktop.
Attachments to Doctrine Jira Issue DDC-1742 - https://github.com/doctrine/doctrine2/issues/2392
<?php
namespace Doctrine\Tests\ORM\Functional\Ticket;
/**
* @group DDC-1742
*/
class DDC1742Test extends \Doctrine\Tests\OrmFunctionalTestCase
{
protected function setUp()
{
parent::setUp();
try {
$this->_schemaTool->createSchema(array(
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1742Dog'),
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1742Cat'),
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1742Animal'),
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1742Person'),
));
} catch (\Exception $ignored) {
}
}
public function testIssue()
{
$person1 = new DDC1742Person();
$dog1 = new DDC1742Dog();
$person1->addPet($dog1);
$this->_em->persist($person1);
$this->_em->persist($dog1);
$this->_em->flush();
$this->_em->remove($person1);
$this->_em->flush();
}
}
/**
* @DiscriminatorColumn(name="type", type="string")
* @DiscriminatorMap({"cat" = "DDC1742Cat", "dog" = "DDC1742Dog"})
* @Entity
* @InheritanceType("SINGLE_TABLE")
*/
class DDC1742Animal
{
/** @Column(type="integer") @GeneratedValue @Id */
protected $id;
/** @ManyToOne(targetEntity="DDC1742Person",inversedBy="pets") */
protected $owner;
public function setOwner(DDC1742Person $person)
{
$this->owner = $person;
}
}
/** @Entity */
class DDC1742Cat extends DDC1742Animal
{
}
/** @Entity */
class DDC1742Dog extends DDC1742Animal
{
}
/** @Entity */
class DDC1742Person
{
/** @Column(type="integer") @GeneratedValue @Id */
protected $id;
/** @OneToMany(targetEntity="DDC1742Animal",mappedBy="owner",cascade={"delete"}) */
protected $pets;
public function addPet(DDC1742Animal $animal)
{
$animal->setOwner($this);
$this->pets[] = $animal;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment