2010-01-27 23:56:56 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Doctrine\Tests\ORM\Functional\Ticket;
|
|
|
|
|
|
|
|
require_once __DIR__ . '/../../../TestInit.php';
|
|
|
|
|
|
|
|
class DDC279Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
|
|
|
{
|
|
|
|
protected function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
$this->_schemaTool->createSchema(array(
|
2010-01-30 00:24:29 +03:00
|
|
|
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC279EntityXAbstract'),
|
2010-01-27 23:56:56 +03:00
|
|
|
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC279EntityX'),
|
|
|
|
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC279EntityY'),
|
2010-01-30 00:24:29 +03:00
|
|
|
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC279EntityZ'),
|
2010-01-27 23:56:56 +03:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group DDC-279
|
|
|
|
*/
|
|
|
|
public function testDDC279()
|
|
|
|
{
|
|
|
|
$x = new DDC279EntityX();
|
|
|
|
$y = new DDC279EntityY();
|
|
|
|
$z = new DDC279EntityZ();
|
|
|
|
|
|
|
|
$x->data = 'X';
|
|
|
|
$y->data = 'Y';
|
|
|
|
$z->data = 'Z';
|
|
|
|
|
|
|
|
$x->y = $y;
|
|
|
|
$y->z = $z;
|
|
|
|
|
|
|
|
$this->_em->persist($x);
|
|
|
|
$this->_em->persist($y);
|
|
|
|
$this->_em->persist($z);
|
|
|
|
|
|
|
|
$this->_em->flush();
|
|
|
|
$this->_em->clear();
|
|
|
|
|
2010-01-30 00:24:29 +03:00
|
|
|
$query = $this->_em->createQuery(
|
2010-01-27 23:56:56 +03:00
|
|
|
'SELECT x, y, z FROM Doctrine\Tests\ORM\Functional\Ticket\DDC279EntityX x '.
|
2010-01-30 00:24:29 +03:00
|
|
|
'INNER JOIN x.y y INNER JOIN y.z z WHERE x.id = ?1'
|
|
|
|
)->setParameter(1, $x->id);
|
2011-12-20 01:56:19 +04:00
|
|
|
|
2010-01-30 00:24:29 +03:00
|
|
|
$result = $query->getResult();
|
2011-12-20 01:56:19 +04:00
|
|
|
|
2010-01-30 00:24:29 +03:00
|
|
|
$expected1 = 'Y';
|
|
|
|
$expected2 = 'Z';
|
|
|
|
|
|
|
|
$this->assertEquals(1, count($result));
|
2011-12-20 01:56:19 +04:00
|
|
|
|
2010-01-30 00:24:29 +03:00
|
|
|
$this->assertEquals($expected1, $result[0]->y->data);
|
|
|
|
$this->assertEquals($expected2, $result[0]->y->z->data);
|
2010-01-27 23:56:56 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-30 00:24:29 +03:00
|
|
|
|
2010-01-27 23:56:56 +03:00
|
|
|
/**
|
|
|
|
* @Entity
|
2010-01-30 00:24:29 +03:00
|
|
|
* @InheritanceType("JOINED")
|
|
|
|
* @DiscriminatorColumn(name="discr", type="string")
|
|
|
|
* @DiscriminatorMap({"DDC279EntityX" = "DDC279EntityX"})
|
2010-01-27 23:56:56 +03:00
|
|
|
*/
|
2010-01-30 00:24:29 +03:00
|
|
|
abstract class DDC279EntityXAbstract
|
2010-01-27 23:56:56 +03:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @Id
|
2010-04-10 02:00:36 +04:00
|
|
|
* @GeneratedValue
|
2010-01-27 23:56:56 +03:00
|
|
|
* @Column(name="id", type="integer")
|
|
|
|
*/
|
|
|
|
public $id;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @column(type="string")
|
|
|
|
*/
|
|
|
|
public $data;
|
|
|
|
|
2010-01-30 00:24:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Entity
|
|
|
|
*/
|
|
|
|
class DDC279EntityX extends DDC279EntityXAbstract
|
|
|
|
{
|
2010-01-27 23:56:56 +03:00
|
|
|
/**
|
2010-01-30 00:24:29 +03:00
|
|
|
* @OneToOne(targetEntity="DDC279EntityY")
|
2010-01-27 23:56:56 +03:00
|
|
|
* @JoinColumn(name="y_id", referencedColumnName="id")
|
|
|
|
*/
|
|
|
|
public $y;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Entity
|
|
|
|
*/
|
|
|
|
class DDC279EntityY
|
|
|
|
{
|
|
|
|
/**
|
2010-04-10 02:00:36 +04:00
|
|
|
* @Id @GeneratedValue
|
2010-01-27 23:56:56 +03:00
|
|
|
* @Column(name="id", type="integer")
|
|
|
|
*/
|
|
|
|
public $id;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @column(type="string")
|
|
|
|
*/
|
|
|
|
public $data;
|
|
|
|
|
|
|
|
/**
|
2010-01-30 00:24:29 +03:00
|
|
|
* @OneToOne(targetEntity="DDC279EntityZ")
|
2010-01-27 23:56:56 +03:00
|
|
|
* @JoinColumn(name="z_id", referencedColumnName="id")
|
|
|
|
*/
|
|
|
|
public $z;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Entity
|
|
|
|
*/
|
|
|
|
class DDC279EntityZ
|
|
|
|
{
|
|
|
|
/**
|
2010-04-10 02:00:36 +04:00
|
|
|
* @Id @GeneratedValue
|
2010-01-27 23:56:56 +03:00
|
|
|
* @Column(name="id", type="integer")
|
|
|
|
*/
|
|
|
|
public $id;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @column(type="string")
|
|
|
|
*/
|
|
|
|
public $data;
|
|
|
|
}
|