Commit 077d9fb0 authored by beberlei's avatar beberlei

[2.0] DDC-135 DDC-177 Implement missing WITH clause, disallow use of ON clause...

[2.0] DDC-135 DDC-177 Implement missing WITH clause, disallow use of ON clause by throwing an exception
parent 446a2ea7
......@@ -33,6 +33,7 @@ use Doctrine\ORM\Query\AST\PathExpression;
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Jonathan Wage <jonwage@gmail.com>
* @author Roman Borschel <roman@code-factory.org>
* @author Benjamin Eberlei <kontakt@beberlei.de>
*/
class QueryException extends \Doctrine\Common\DoctrineException
{
......@@ -84,4 +85,13 @@ class QueryException extends \Doctrine\Common\DoctrineException
"in class ".$assoc->sourceEntityName." assocation ".$assoc->sourceFieldName
);
}
public static function overwritingJoinConditionsNotYetSupported($assoc)
{
return new self(
"Unsupported query operation: It is not yet possible to overwrite the join ".
"conditions in class ".$assoc->sourceEntityName." assocation ".$assoc->sourceFieldName.". ".
"Use WITH to append additional join conditions to the association."
);
}
}
\ No newline at end of file
......@@ -30,11 +30,14 @@ use Doctrine\ORM\Query,
* the corresponding SQL.
*
* @author Roman Borschel <roman@code-factory.org>
* @author Benjamin Eberlei <kontakt@beberlei.de>
* @since 2.0
*/
class SqlWalker implements TreeWalker
{
/** The ResultSetMapping. */
/**
* @var ResultSetMapping
*/
private $_rsm;
/** Counter for generating unique column aliases. */
......@@ -47,13 +50,19 @@ class SqlWalker implements TreeWalker
/** Counter for SQL parameter positions. */
private $_sqlParamIndex = 1;
/** The ParserResult. */
/**
* @var ParserResult
*/
private $_parserResult;
/** The EntityManager. */
/**
* @var EntityManager
*/
private $_em;
/** The Connection of the EntityManager. */
/**
* @var Doctrine\DBAL\Connection
*/
private $_conn;
/**
......@@ -741,6 +750,17 @@ class SqlWalker implements TreeWalker
}
}
// Handle ON / WITH clause
if ($join->conditionalExpression !== null) {
if ($join->whereType == AST\Join::JOIN_WHERE_ON) {
throw QueryException::overwritingJoinConditionsNotYetSupported($assoc);
} else {
$sql .= ' AND (' . implode(' OR ',
array_map(array($this, 'walkConditionalTerm'), $join->conditionalExpression->conditionalTerms)
). ')';
}
}
$discrSql = $this->_generateDiscriminatorColumnConditionSql($joinedDqlAlias);
if ($discrSql) {
......
......@@ -192,6 +192,34 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
);
}
/**
* @group DDC-135
*/
public function testSupportsJoinAndWithClauseRestriction()
{
$this->assertSqlGeneration(
"SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u LEFT JOIN u.articles a WITH a.topic LIKE '%foo%'",
"SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3 FROM cms_users c0_ LEFT JOIN cms_articles c1_ ON c0_.id = c1_.user_id AND (c1_.topic LIKE '%foo%')"
);
$this->assertSqlGeneration(
"SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u INNER JOIN u.articles a WITH a.topic LIKE '%foo%'",
"SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3 FROM cms_users c0_ INNER JOIN cms_articles c1_ ON c0_.id = c1_.user_id AND (c1_.topic LIKE '%foo%')"
);
}
/**
* @group DDC-135
* @group DDC-177
*/
public function testJoinOnClause_NotYetSupported_ThrowsException()
{
$this->setExpectedException('Doctrine\ORM\Query\QueryException');
$sql = $this->_em->createQuery(
"SELECT u, a FROM Doctrine\Tests\Models\CMS\CmsUser u LEFT JOIN u.articles a ON a.topic LIKE '%foo%'"
)->getSql();
}
public function testSupportsMultipleJoins()
{
$this->assertSqlGeneration(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment