1
0
mirror of synced 2024-12-13 22:56:04 +03:00

DDC-1194 - Improve error handling for DQL INSTANCE OF

This commit is contained in:
Benjamin Eberlei 2011-06-05 10:48:21 +02:00
parent 2c9a12771b
commit 1038a866a4
3 changed files with 32 additions and 0 deletions

View File

@ -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.");
}
}

View File

@ -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]);
}

View File

@ -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()
{