diff --git a/lib/Doctrine/ORM/Persisters/SingleTablePersister.php b/lib/Doctrine/ORM/Persisters/SingleTablePersister.php index 3f7574cba..ddeb1b108 100644 --- a/lib/Doctrine/ORM/Persisters/SingleTablePersister.php +++ b/lib/Doctrine/ORM/Persisters/SingleTablePersister.php @@ -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]); diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index 289e0200d..323599927 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -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); diff --git a/tests/Doctrine/Tests/ORM/Functional/SingleTableInheritanceTest.php b/tests/Doctrine/Tests/ORM/Functional/SingleTableInheritanceTest.php index 84705831c..b2bd382c6 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SingleTableInheritanceTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SingleTableInheritanceTest.php @@ -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()