test discriminator column
This commit is contained in:
parent
0cc2583a02
commit
68665af6e8
@ -124,6 +124,12 @@ class ResultSetMappingBuilder extends ResultSetMapping
|
|||||||
|
|
||||||
$this->addEntityResult($class->name, $alias);
|
$this->addEntityResult($class->name, $alias);
|
||||||
|
|
||||||
|
if ($classMetadata->discriminatorColumn) {
|
||||||
|
$discriminatorColumn = $classMetadata->discriminatorColumn;
|
||||||
|
$this->setDiscriminatorColumn($alias, $discriminatorColumn['name']);
|
||||||
|
$this->addMetaResult($alias, $discriminatorColumn['name'], $discriminatorColumn['fieldName']);
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($classMetadata->getColumnNames() as $key => $columnName) {
|
foreach ($classMetadata->getColumnNames() as $key => $columnName) {
|
||||||
$propertyName = $classMetadata->getFieldName($columnName);
|
$propertyName = $classMetadata->getFieldName($columnName);
|
||||||
$this->addFieldResult($alias, $columnName, $propertyName);
|
$this->addFieldResult($alias, $columnName, $propertyName);
|
||||||
@ -148,6 +154,12 @@ class ResultSetMappingBuilder extends ResultSetMapping
|
|||||||
$shortName = $classMetadata->reflClass->getShortName();
|
$shortName = $classMetadata->reflClass->getShortName();
|
||||||
$alias = strtolower($shortName[0]) . $key;
|
$alias = strtolower($shortName[0]) . $key;
|
||||||
|
|
||||||
|
if (isset($entityMapping['discriminatorColumn']) && $entityMapping['discriminatorColumn']) {
|
||||||
|
$discriminatorColumn = $entityMapping['discriminatorColumn'];
|
||||||
|
$this->setDiscriminatorColumn($alias, $discriminatorColumn);
|
||||||
|
$this->addMetaResult($alias, $discriminatorColumn, $discriminatorColumn);
|
||||||
|
}
|
||||||
|
|
||||||
$this->addEntityResult($classMetadata->name, $alias);
|
$this->addEntityResult($classMetadata->name, $alias);
|
||||||
if (isset($entityMapping['fields']) && !empty($entityMapping['fields'])) {
|
if (isset($entityMapping['fields']) && !empty($entityMapping['fields'])) {
|
||||||
foreach ($entityMapping['fields'] as $field) {
|
foreach ($entityMapping['fields'] as $field) {
|
||||||
|
@ -35,7 +35,7 @@ use Doctrine\Common\Collections\ArrayCollection;
|
|||||||
* @NamedNativeQuery(
|
* @NamedNativeQuery(
|
||||||
* name = "fetchUserPhonenumberCount",
|
* name = "fetchUserPhonenumberCount",
|
||||||
* resultSetMapping= "mappingUserPhonenumberCount",
|
* resultSetMapping= "mappingUserPhonenumberCount",
|
||||||
* query = "SELECT id, name, status, COUNT(phonenumber) AS numPhones FROM cms_users INNER JOIN cms_phonenumbers ON id = user_id WHERE username IN (?) GROUP BY status, user_id ORDER BY username"
|
* query = "SELECT id, name, status, COUNT(phonenumber) AS numPhones FROM cms_users INNER JOIN cms_phonenumbers ON id = user_id WHERE username IN (?) GROUP BY id, name, status ORDER BY username"
|
||||||
* ),
|
* ),
|
||||||
* })
|
* })
|
||||||
*
|
*
|
||||||
|
@ -13,7 +13,37 @@ namespace Doctrine\Tests\Models\Company;
|
|||||||
* @DiscriminatorMap({
|
* @DiscriminatorMap({
|
||||||
* "person" = "CompanyPerson",
|
* "person" = "CompanyPerson",
|
||||||
* "manager" = "CompanyManager",
|
* "manager" = "CompanyManager",
|
||||||
* "employee" = "CompanyEmployee"})
|
* "employee" = "CompanyEmployee"
|
||||||
|
* })
|
||||||
|
*
|
||||||
|
* @NamedNativeQueries({
|
||||||
|
* @NamedNativeQuery(
|
||||||
|
* name = "fetchAllWithResultClass",
|
||||||
|
* resultClass = "__CLASS__",
|
||||||
|
* query = "SELECT id, name, discr FROM company_persons ORDER BY name"
|
||||||
|
* ),
|
||||||
|
* @NamedNativeQuery(
|
||||||
|
* name = "fetchAllWithSqlResultSetMapping",
|
||||||
|
* resultSetMapping= "mappingFetchAll",
|
||||||
|
* query = "SELECT id, name, discr AS discriminator FROM company_persons ORDER BY name"
|
||||||
|
* )
|
||||||
|
* })
|
||||||
|
*
|
||||||
|
* @SqlResultSetMappings({
|
||||||
|
* @SqlResultSetMapping(
|
||||||
|
* name = "mappingFetchAll",
|
||||||
|
* entities= {
|
||||||
|
* @EntityResult(
|
||||||
|
* entityClass = "__CLASS__",
|
||||||
|
* discriminatorColumn = "discriminator",
|
||||||
|
* fields = {
|
||||||
|
* @FieldResult("id"),
|
||||||
|
* @FieldResult("name"),
|
||||||
|
* }
|
||||||
|
* )
|
||||||
|
* }
|
||||||
|
* )
|
||||||
|
* })
|
||||||
*/
|
*/
|
||||||
class CompanyPerson
|
class CompanyPerson
|
||||||
{
|
{
|
||||||
|
@ -10,6 +10,7 @@ use Doctrine\Tests\Models\CMS\CmsAddress;
|
|||||||
use Doctrine\Tests\Models\CMS\CmsEmail;
|
use Doctrine\Tests\Models\CMS\CmsEmail;
|
||||||
use Doctrine\Tests\Models\Company\CompanyFixContract;
|
use Doctrine\Tests\Models\Company\CompanyFixContract;
|
||||||
use Doctrine\Tests\Models\Company\CompanyEmployee;
|
use Doctrine\Tests\Models\Company\CompanyEmployee;
|
||||||
|
use Doctrine\Tests\Models\Company\CompanyPerson;
|
||||||
|
|
||||||
require_once __DIR__ . '/../../TestInit.php';
|
require_once __DIR__ . '/../../TestInit.php';
|
||||||
|
|
||||||
@ -24,6 +25,7 @@ class NativeQueryTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
|||||||
|
|
||||||
protected function setUp() {
|
protected function setUp() {
|
||||||
$this->useModelSet('cms');
|
$this->useModelSet('cms');
|
||||||
|
$this->useModelSet('company');
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
$this->platform = $this->_em->getConnection()->getDatabasePlatform();
|
$this->platform = $this->_em->getConnection()->getDatabasePlatform();
|
||||||
}
|
}
|
||||||
@ -546,4 +548,52 @@ class NativeQueryTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
|||||||
$this->assertEquals(1, $result[1]['numPhones']);
|
$this->assertEquals(1, $result[1]['numPhones']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group DDC-1663
|
||||||
|
*/
|
||||||
|
public function testNativeNamedQueryInheritance()
|
||||||
|
{
|
||||||
|
$person = new CompanyPerson;
|
||||||
|
$person->setName('Fabio B. Silva');
|
||||||
|
|
||||||
|
$employee = new CompanyEmployee;
|
||||||
|
$employee->setName('Fabio Silva');
|
||||||
|
$employee->setSalary(100000);
|
||||||
|
$employee->setDepartment('IT');
|
||||||
|
|
||||||
|
$this->_em->persist($person);
|
||||||
|
$this->_em->persist($employee);
|
||||||
|
|
||||||
|
$this->_em->flush();
|
||||||
|
$this->_em->clear();
|
||||||
|
|
||||||
|
$repository = $this->_em->getRepository('Doctrine\Tests\Models\Company\CompanyPerson');
|
||||||
|
|
||||||
|
$result = $repository->createNativeNamedQuery('fetchAllWithSqlResultSetMapping')
|
||||||
|
->getResult();
|
||||||
|
|
||||||
|
$this->assertEquals(2, count($result));
|
||||||
|
$this->assertInstanceOf('Doctrine\Tests\Models\Company\CompanyPerson', $result[0]);
|
||||||
|
$this->assertInstanceOf('Doctrine\Tests\Models\Company\CompanyEmployee', $result[1]);
|
||||||
|
$this->assertTrue(is_numeric($result[0]->getId()));
|
||||||
|
$this->assertTrue(is_numeric($result[1]->getId()));
|
||||||
|
$this->assertEquals('Fabio B. Silva', $result[0]->getName());
|
||||||
|
$this->assertEquals('Fabio Silva', $result[1]->getName());
|
||||||
|
|
||||||
|
|
||||||
|
$this->_em->clear();
|
||||||
|
|
||||||
|
|
||||||
|
$result = $repository->createNativeNamedQuery('fetchAllWithResultClass')
|
||||||
|
->getResult();
|
||||||
|
|
||||||
|
$this->assertEquals(2, count($result));
|
||||||
|
$this->assertInstanceOf('Doctrine\Tests\Models\Company\CompanyPerson', $result[0]);
|
||||||
|
$this->assertInstanceOf('Doctrine\Tests\Models\Company\CompanyEmployee', $result[1]);
|
||||||
|
$this->assertTrue(is_numeric($result[0]->getId()));
|
||||||
|
$this->assertTrue(is_numeric($result[1]->getId()));
|
||||||
|
$this->assertEquals('Fabio B. Silva', $result[0]->getName());
|
||||||
|
$this->assertEquals('Fabio Silva', $result[1]->getName());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user