-
-
Save doctrinebot/521476aa7ae2b8d3f8d2 to your computer and use it in GitHub Desktop.
Attachments to Doctrine Jira Issue DDC-218 - https://github.com/doctrine/doctrine2/issues/2872
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Doctrine\Tests\ORM\Functional\Ticket; | |
use Doctrine\Common\Collections\ArrayCollection; | |
require_once __DIR__ . '/../../../TestInit.php'; | |
class DDC218Test extends \Doctrine\Tests\OrmFunctionalTestCase | |
{ | |
protected function setUp() | |
{ | |
parent::setUp(); | |
$this->_schemaTool->createSchema(array( | |
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC218Property'), | |
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC218PropertyOption') | |
)); | |
} | |
public function testIssue() | |
{ | |
$this->_em->getConnection()->getConfiguration()->setSqlLogger(new \Doctrine\DBAL\Logging\EchoSqlLogger); | |
$prop = new DDC218Property; | |
$option1 = new DDC218PropertyOption; | |
$option2 = new DDC218PropertyOption; | |
$prop->addOption($option1); | |
$prop->addOption($option2); | |
$option1->setProperty($prop); | |
$option2->setProperty($prop); | |
$this->_em->persist($prop); | |
$this->_em->persist($option1); | |
$this->_em->persist($option2); | |
$this->_em->flush(); | |
$this->assertEquals(1, $prop->getVersion()); | |
$this->assertEquals(1, $option1->getVersion()); | |
$this->assertEquals(1, $option2->getVersion()); | |
$this->_em->clear(); | |
$prop2 = $this->_em->find(__NAMESPACE__ . '\DDC218Property', $prop->getId()); | |
$this->assertEquals(2, $prop2->getOptions()->count()); // triggers lazy-load | |
} | |
} | |
/** @MappedSuperclass */ | |
abstract class DDC218AbstractBase | |
{ | |
/** | |
* @Id @Column(type="integer") | |
* @GeneratedValue(strategy="AUTO") | |
* @var integer | |
*/ | |
private $id; | |
/** | |
* @Version @Column(name="version", type="integer") | |
* @var integer | |
*/ | |
private $version; | |
function getId() {return $this->id;} | |
function getVersion() {return $this->version;} | |
} | |
/** @Entity @Table(name="ddc218_properties") */ | |
class DDC218Property extends DDC218AbstractBase | |
{ | |
/** | |
* @OneToMany(targetEntity="DDC218PropertyOption", mappedBy="property") | |
*/ | |
private $options; | |
public function __construct() { | |
$this->options = new ArrayCollection; | |
} | |
function addOption($option) { | |
$this->options[] = $option; | |
} | |
function getOptions() {return $this->options;} | |
} | |
/** @Entity @Table(name="ddc218_propoptions") */ | |
class DDC218PropertyOption extends DDC218AbstractBase | |
{ | |
/** | |
* @ManyToOne(targetEntity="DDC218Property") | |
* @JoinColumn(name="property_id", referencedColumnName="id") | |
*/ | |
private $property; | |
function getProperty() {return $this->property;} | |
function setProperty($prop) {$this->property = $prop;} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment