Skip to content

Instantly share code, notes, and snippets.

@doctrinebot
Created December 13, 2015 18:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save doctrinebot/fc2f5943c39332f7b721 to your computer and use it in GitHub Desktop.
Save doctrinebot/fc2f5943c39332f7b721 to your computer and use it in GitHub Desktop.
Attachments to Doctrine Jira Issue DDC-135 - https://github.com/doctrine/doctrine2/issues/1967
Property changes on: .
___________________________________________________________________
Modified: svn:ignore
- build
+ reports
logs
build
dist
Index: tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php
===================================================================
--- tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php (revision 7156)
+++ tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php (working copy)
@@ -192,6 +192,34 @@
);
}
+ /**
+ * @group DDC-135
+ */
+ public function testSupportsLeftJoinWithOnClause()
+ {
+ $this->assertSqlGeneration(
+ "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u LEFT JOIN u.articles a ON 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 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%')"
+ );
+ }
+
+ /**
+ * @group DDC-135
+ * @group DDC-177
+ */
+ public function testThrowsExceptionOnFetchJOineDLeftJoinWithOnRestriction()
+ {
+ $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(
Index: lib/Doctrine/ORM/Query/QueryException.php
===================================================================
--- lib/Doctrine/ORM/Query/QueryException.php (revision 7156)
+++ lib/Doctrine/ORM/Query/QueryException.php (working copy)
@@ -84,4 +84,13 @@
"in class ".$assoc->sourceEntityName." assocation ".$assoc->sourceFieldName
);
}
+
+ /**
+ * @param Doctrine\ORM\Mapping\AssociationMapping $assoc
+ */
+ public static function restrictingJoinClauseWithFetchJoinNotAllowed($assoc)
+ {
+ return new self('Restricting or overwriting the join on clause is not allowed with a fetch joined association '.
+ 'in class '.$assoc->sourceEntityName." assocation ".$assoc->sourceFieldName);
+ }
}
\ No newline at end of file
Index: lib/Doctrine/ORM/Query/SqlWalker.php
===================================================================
--- lib/Doctrine/ORM/Query/SqlWalker.php (revision 7156)
+++ lib/Doctrine/ORM/Query/SqlWalker.php (working copy)
@@ -34,7 +34,9 @@
*/
class SqlWalker implements TreeWalker
{
- /** The ResultSetMapping. */
+ /**
+ * @var ResultSetMapping
+ */
private $_rsm;
/** Counter for generating unique column aliases. */
@@ -47,13 +49,19 @@
/** 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 +749,16 @@
}
}
+ if ($join->conditionalExpression !== null) {
+ if ($this->_query->getHydrationMode() == Query::HYDRATE_OBJECT && isset($this->_rsm->aliasMap[$joinedDqlAlias])) {
+ throw QueryException::restrictingJoinClauseWithFetchJoinNotAllowed($assoc);
+ }
+
+ $sql .= ' AND (' . implode(' OR ',
+ array_map(array($this, 'walkConditionalTerm'), $join->conditionalExpression->conditionalTerms)
+ ). ')';
+ }
+
$discrSql = $this->_generateDiscriminatorColumnConditionSql($joinedDqlAlias);
if ($discrSql) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment