2010-02-27 20:48:18 +03:00
|
|
|
<?php
|
|
|
|
namespace Doctrine\Tests\ORM\Functional\Ticket;
|
|
|
|
|
|
|
|
use Doctrine\ORM\Query;
|
|
|
|
|
|
|
|
require_once __DIR__ . '/../../../TestInit.php';
|
|
|
|
|
|
|
|
class DDC371Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
|
|
|
{
|
|
|
|
protected function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
2010-04-01 00:47:35 +04:00
|
|
|
//$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger);
|
2010-02-27 20:48:18 +03:00
|
|
|
$this->_schemaTool->createSchema(array(
|
|
|
|
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC371Parent'),
|
|
|
|
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC371Child')
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testIssue()
|
|
|
|
{
|
|
|
|
$parent = new DDC371Parent;
|
|
|
|
$parent->data = 'parent';
|
|
|
|
$parent->children = new \Doctrine\Common\Collections\ArrayCollection;
|
2011-12-20 01:56:19 +04:00
|
|
|
|
2010-02-27 20:48:18 +03:00
|
|
|
$child = new DDC371Child;
|
|
|
|
$child->data = 'child';
|
2011-12-20 01:56:19 +04:00
|
|
|
|
2010-02-27 20:48:18 +03:00
|
|
|
$child->parent = $parent;
|
|
|
|
$parent->children->add($child);
|
2011-12-20 01:56:19 +04:00
|
|
|
|
2010-02-27 20:48:18 +03:00
|
|
|
$this->_em->persist($parent);
|
|
|
|
$this->_em->persist($child);
|
2011-12-20 01:56:19 +04:00
|
|
|
|
2010-02-27 20:48:18 +03:00
|
|
|
$this->_em->flush();
|
|
|
|
$this->_em->clear();
|
2011-12-20 01:56:19 +04:00
|
|
|
|
2010-02-27 20:48:18 +03:00
|
|
|
$children = $this->_em->createQuery('select c,p from '.__NAMESPACE__.'\DDC371Child c '
|
|
|
|
. 'left join c.parent p where c.id = 1 and p.id = 1')
|
|
|
|
->setHint(Query::HINT_REFRESH, true)
|
|
|
|
->getResult();
|
2011-12-20 01:56:19 +04:00
|
|
|
|
2010-02-27 20:48:18 +03:00
|
|
|
$this->assertEquals(1, count($children));
|
2011-07-26 13:38:09 +04:00
|
|
|
$this->assertNotInstanceOf('Doctrine\ORM\Proxy\Proxy', $children[0]->parent);
|
2010-02-27 20:48:18 +03:00
|
|
|
$this->assertFalse($children[0]->parent->children->isInitialized());
|
|
|
|
$this->assertEquals(0, $children[0]->parent->children->unwrap()->count());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @Entity */
|
|
|
|
class DDC371Child {
|
|
|
|
/** @Id @Column(type="integer") @GeneratedValue */
|
|
|
|
private $id;
|
|
|
|
/** @Column(type="string") */
|
|
|
|
public $data;
|
2010-04-10 02:00:36 +04:00
|
|
|
/** @ManyToOne(targetEntity="DDC371Parent", inversedBy="children") @JoinColumn(name="parentId") */
|
2010-02-27 20:48:18 +03:00
|
|
|
public $parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @Entity */
|
|
|
|
class DDC371Parent {
|
|
|
|
/** @Id @Column(type="integer") @GeneratedValue */
|
|
|
|
private $id;
|
|
|
|
/** @Column(type="string") */
|
|
|
|
public $data;
|
|
|
|
/** @OneToMany(targetEntity="DDC371Child", mappedBy="parent") */
|
|
|
|
public $children;
|
|
|
|
}
|
|
|
|
|