DDC-1194 - Improve error handling for DQL INSTANCE OF
This commit is contained in:
parent
2c9a12771b
commit
1038a866a4
@ -135,4 +135,10 @@ class QueryException extends \Doctrine\ORM\ORMException
|
||||
"in the query."
|
||||
);
|
||||
}
|
||||
|
||||
public static function instanceOfUnrelatedClass($className, $rootClass)
|
||||
{
|
||||
return new self("Cannot check if a child of '" . $rootClass . "' is instanceof '" . $className . "', " .
|
||||
"inheritance hierachy exists between these two classes.");
|
||||
}
|
||||
}
|
@ -1657,6 +1657,10 @@ class SqlWalker implements TreeWalker
|
||||
$sql .= $this->_conn->quote($class->discriminatorValue);
|
||||
} else {
|
||||
$discrMap = array_flip($class->discriminatorMap);
|
||||
if (!isset($discrMap[$entityClassName])) {
|
||||
throw QueryException::instanceOfUnrelatedClass($entityClassName, $class->rootEntityName);
|
||||
}
|
||||
|
||||
$sql .= $this->_conn->quote($discrMap[$entityClassName]);
|
||||
}
|
||||
|
||||
|
@ -383,6 +383,28 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
|
||||
"SELECT c0_.id AS id0, c0_.name AS name1, c0_.discr AS discr2 FROM company_persons c0_ WHERE c0_.discr = 'employee'"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-1194
|
||||
*/
|
||||
public function testSupportsInstanceOfExpressionsInWherePartPrefixedSlash()
|
||||
{
|
||||
$this->assertSqlGeneration(
|
||||
"SELECT u FROM Doctrine\Tests\Models\Company\CompanyPerson u WHERE u INSTANCE OF \Doctrine\Tests\Models\Company\CompanyEmployee",
|
||||
"SELECT c0_.id AS id0, c0_.name AS name1, c0_.discr AS discr2 FROM company_persons c0_ WHERE c0_.discr = 'employee'"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-1194
|
||||
*/
|
||||
public function testSupportsInstanceOfExpressionsInWherePartWithUnrelatedClass()
|
||||
{
|
||||
$this->assertInvalidSqlGeneration(
|
||||
"SELECT u FROM Doctrine\Tests\Models\Company\CompanyPerson u WHERE u INSTANCE OF \Doctrine\Tests\Models\CMS\CmsUser",
|
||||
"Doctrine\ORM\Query\QueryException"
|
||||
);
|
||||
}
|
||||
|
||||
public function testSupportsInstanceOfExpressionsInWherePartInDeeperLevel()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user