2014-06-17 14:45:59 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Doctrine\Tests\ORM\Functional\Ticket;
|
|
|
|
|
|
|
|
use Doctrine\ORM\AbstractQuery;
|
|
|
|
use Doctrine\ORM\Internal\Hydration\HydrationException;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group DDC-2306
|
|
|
|
*/
|
|
|
|
class DDC3170Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
2016-05-11 01:55:12 +07:00
|
|
|
protected function setUp()
|
2014-06-17 14:45:59 +02:00
|
|
|
{
|
2016-05-11 01:55:12 +07:00
|
|
|
parent::setUp();
|
2014-06-17 14:45:59 +02:00
|
|
|
|
|
|
|
$this->_schemaTool->createSchema(
|
2016-12-07 23:33:41 +01:00
|
|
|
[
|
2016-12-08 18:01:04 +01:00
|
|
|
$this->_em->getClassMetadata(DDC3170AbstractEntityJoined::class),
|
|
|
|
$this->_em->getClassMetadata(DDC3170ProductJoined::class),
|
|
|
|
$this->_em->getClassMetadata(DDC3170AbstractEntitySingleTable::class),
|
|
|
|
$this->_em->getClassMetadata(DDC3170ProductSingleTable::class),
|
2016-12-07 23:33:41 +01:00
|
|
|
]
|
2014-06-17 14:45:59 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests that the discriminator column is correctly read from the meta mappings when fetching a
|
|
|
|
* child from an inheritance mapped class.
|
|
|
|
*
|
|
|
|
* The simple object hydration maps the type field to a field alias like type2. This mapping needs
|
|
|
|
* to be considered when loading the discriminator column's value from the SQL result.
|
|
|
|
*
|
|
|
|
* {@see \Doctrine\ORM\Internal\Hydration\SimpleObjectHydrator::hydrateRowData()}
|
|
|
|
*/
|
|
|
|
public function testIssue()
|
|
|
|
{
|
|
|
|
$productJoined = new DDC3170ProductJoined();
|
|
|
|
$productSingleTable = new DDC3170ProductSingleTable();
|
2017-05-31 07:59:04 +02:00
|
|
|
|
2014-06-17 14:45:59 +02:00
|
|
|
$this->_em->persist($productJoined);
|
|
|
|
$this->_em->persist($productSingleTable);
|
|
|
|
$this->_em->flush();
|
|
|
|
$this->_em->clear();
|
|
|
|
|
2017-05-31 16:36:31 +02:00
|
|
|
$result = $this->_em->createQueryBuilder()
|
2017-05-31 08:05:01 +02:00
|
|
|
->select('p')
|
|
|
|
->from(DDC3170ProductJoined::class, 'p')
|
|
|
|
->getQuery()
|
|
|
|
->getResult(AbstractQuery::HYDRATE_SIMPLEOBJECT);
|
2014-06-17 14:45:59 +02:00
|
|
|
|
2017-05-31 16:36:31 +02:00
|
|
|
self::assertCount(1, $result);
|
|
|
|
self::assertContainsOnly(DDC3170ProductJoined::class, $result);
|
|
|
|
|
|
|
|
$result = $this->_em->createQueryBuilder()
|
2017-05-31 08:05:01 +02:00
|
|
|
->select('p')
|
|
|
|
->from(DDC3170ProductSingleTable::class, 'p')
|
|
|
|
->getQuery()
|
|
|
|
->getResult(AbstractQuery::HYDRATE_SIMPLEOBJECT);
|
2017-05-31 16:36:31 +02:00
|
|
|
|
|
|
|
self::assertCount(1, $result);
|
|
|
|
self::assertContainsOnly(DDC3170ProductSingleTable::class, $result);
|
2014-06-17 14:45:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Entity
|
|
|
|
* @InheritanceType("JOINED")
|
|
|
|
* @DiscriminatorColumn(name="type", type="string")
|
|
|
|
* @DiscriminatorMap({"product" = "DDC3170ProductJoined"})
|
|
|
|
*/
|
|
|
|
abstract class DDC3170AbstractEntityJoined
|
|
|
|
{
|
|
|
|
/** @Id @Column(type="integer") @GeneratedValue */
|
|
|
|
public $id;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Entity
|
|
|
|
*/
|
|
|
|
class DDC3170ProductJoined extends DDC3170AbstractEntityJoined
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Entity
|
|
|
|
* @InheritanceType("SINGLE_TABLE")
|
|
|
|
* @DiscriminatorColumn(name="type", type="string")
|
|
|
|
* @DiscriminatorMap({"product" = "DDC3170ProductSingleTable"})
|
|
|
|
*/
|
|
|
|
abstract class DDC3170AbstractEntitySingleTable
|
|
|
|
{
|
|
|
|
/** @Id @Column(type="integer") @GeneratedValue */
|
|
|
|
public $id;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Entity
|
|
|
|
*/
|
|
|
|
class DDC3170ProductSingleTable extends DDC3170AbstractEntitySingleTable
|
|
|
|
{
|
|
|
|
}
|