[DDC-2224] Rewrite instanceof feature with parameter needle ClassMetadata breaks caching of queries.
This commit is contained in:
parent
edca8c88ea
commit
64b2ecfefc
4 changed files with 27 additions and 20 deletions
|
@ -284,6 +284,10 @@ abstract class AbstractQuery
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($value instanceof Mapping\ClassMetadata) {
|
||||||
|
return $value->name;
|
||||||
|
}
|
||||||
|
|
||||||
return $value;
|
return $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1932,31 +1932,22 @@ class SqlWalker implements TreeWalker
|
||||||
|
|
||||||
foreach ($instanceOfExpr->value as $parameter) {
|
foreach ($instanceOfExpr->value as $parameter) {
|
||||||
if ($parameter instanceof AST\InputParameter) {
|
if ($parameter instanceof AST\InputParameter) {
|
||||||
// We need to modify the parameter value to be its correspondent mapped value
|
$sqlParameterList[] = $this->walkInputParameter($parameter);
|
||||||
$dqlParamKey = $parameter->name;
|
|
||||||
$dqlParam = $this->query->getParameter($dqlParamKey);
|
|
||||||
$paramValue = $this->query->processParameterValue($dqlParam->getValue());
|
|
||||||
|
|
||||||
if ( ! ($paramValue instanceof \Doctrine\ORM\Mapping\ClassMetadata)) {
|
|
||||||
throw QueryException::invalidParameterType('ClassMetadata', get_class($paramValue));
|
|
||||||
}
|
|
||||||
|
|
||||||
$entityClassName = $paramValue->name;
|
|
||||||
} else {
|
} else {
|
||||||
// Get name from ClassMetadata to resolve aliases.
|
// Get name from ClassMetadata to resolve aliases.
|
||||||
$entityClassName = $this->em->getClassMetadata($parameter)->name;
|
$entityClassName = $this->em->getClassMetadata($parameter)->name;
|
||||||
}
|
|
||||||
|
|
||||||
if ($entityClassName == $class->name) {
|
if ($entityClassName == $class->name) {
|
||||||
$sqlParameterList[] = $this->conn->quote($class->discriminatorValue);
|
$sqlParameterList[] = $this->conn->quote($class->discriminatorValue);
|
||||||
} else {
|
} else {
|
||||||
$discrMap = array_flip($class->discriminatorMap);
|
$discrMap = array_flip($class->discriminatorMap);
|
||||||
|
|
||||||
if (!isset($discrMap[$entityClassName])) {
|
if (!isset($discrMap[$entityClassName])) {
|
||||||
throw QueryException::instanceOfUnrelatedClass($entityClassName, $class->rootEntityName);
|
throw QueryException::instanceOfUnrelatedClass($entityClassName, $class->rootEntityName);
|
||||||
|
}
|
||||||
|
|
||||||
|
$sqlParameterList[] = $this->conn->quote($discrMap[$entityClassName]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$sqlParameterList[] = $this->conn->quote($discrMap[$entityClassName]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -163,4 +163,16 @@ class QueryTest extends \Doctrine\Tests\OrmTestCase
|
||||||
$this->assertEquals('cities', $parameter->getName());
|
$this->assertEquals('cities', $parameter->getName());
|
||||||
$this->assertEquals($cities, $parameter->getValue());
|
$this->assertEquals($cities, $parameter->getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group DDC-2224
|
||||||
|
*/
|
||||||
|
public function testProcessParameterValueClassMetadata()
|
||||||
|
{
|
||||||
|
$query = $this->_em->createQuery("SELECT a FROM Doctrine\Tests\Models\CMS\CmsAddress a WHERE a.city IN (:cities)");
|
||||||
|
$this->assertEquals(
|
||||||
|
'Doctrine\Tests\Models\CMS\CmsAddress',
|
||||||
|
$query->processParameterValue($this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress'))
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -482,7 +482,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
|
||||||
{
|
{
|
||||||
$this->assertSqlGeneration(
|
$this->assertSqlGeneration(
|
||||||
"SELECT u FROM Doctrine\Tests\Models\Company\CompanyPerson u WHERE u INSTANCE OF ?1",
|
"SELECT u FROM Doctrine\Tests\Models\Company\CompanyPerson u WHERE u INSTANCE OF ?1",
|
||||||
"SELECT c0_.id AS id0, c0_.name AS name1, c0_.discr AS discr2 FROM company_persons c0_ WHERE c0_.discr IN ('employee')",
|
"SELECT c0_.id AS id0, c0_.name AS name1, c0_.discr AS discr2 FROM company_persons c0_ WHERE c0_.discr IN (?)",
|
||||||
array(), array(1 => $this->_em->getClassMetadata('Doctrine\Tests\Models\Company\CompanyEmployee'))
|
array(), array(1 => $this->_em->getClassMetadata('Doctrine\Tests\Models\Company\CompanyEmployee'))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue