1
0
mirror of synced 2024-12-14 07:06:04 +03:00

DDC-649 - Remove IN queries for empty discriminator values if abstract base class is not part of the discriminator map

This commit is contained in:
Benjamin Eberlei 2010-07-04 13:34:14 +02:00
parent fdf1f1b29e
commit 552865a867
3 changed files with 16 additions and 5 deletions

View File

@ -100,7 +100,11 @@ class SingleTablePersister extends AbstractEntityInheritancePersister
// Append discriminator condition
if ($conditionSql) $conditionSql .= ' AND ';
$values = array($this->_conn->quote($this->_class->discriminatorValue));
$values = array();
if ($this->_class->discriminatorValue !== null) { // discriminators can be 0
$values[] = $this->_conn->quote($this->_class->discriminatorValue);
}
$discrValues = array_flip($this->_class->discriminatorMap);
foreach ($this->_class->subClasses as $subclassName) {
$values[] = $this->_conn->quote($discrValues[$subclassName]);

View File

@ -320,7 +320,10 @@ class SqlWalker implements TreeWalker
if ($class->isInheritanceTypeSingleTable()) {
$conn = $this->_em->getConnection();
$values = array($conn->quote($class->discriminatorValue));
$values = array();
if ($class->discriminatorValue !== null) { // discrimnators can be 0
$values[] = $conn->quote($class->discriminatorValue);
}
foreach ($class->subClasses as $subclassName) {
$values[] = $conn->quote($this->_em->getClassMetadata($subclassName)->discriminatorValue);

View File

@ -219,9 +219,13 @@ class SingleTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase
$contracts = $this->_em->createQuery('SELECT c FROM Doctrine\Tests\Models\Company\CompanyContract c ORDER BY c.id')->getScalarResult();
$this->assertEquals('fix', $contracts[0]['c_discr']);
$this->assertEquals('flexible', $contracts[1]['c_discr']);
$this->assertEquals('flexultra', $contracts[2]['c_discr']);
$discrValues = \array_map(function($a) {
return $a['c_discr'];
}, $contracts);
sort($discrValues);
$this->assertEquals(array('fix', 'flexible', 'flexultra'), $discrValues);
}
public function testQueryChildClassWithCondition()