Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

DDC 1430 #193

Merged
merged 2 commits into from

2 participants

@FabioBatSilva

Hello all

I think this patch fix the problem with foreign keys,

@beberlei, please take a look and tell me what you think about

Thanks...

@beberlei
Owner

That was fast, thanks!

@beberlei beberlei merged commit 43b1e79 into from
@FabioBatSilva

Sorry @beberlei

I'm changing the test case

@elHornair elHornair referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
11 lib/Doctrine/ORM/Query/SqlWalker.php
@@ -22,7 +22,8 @@
use Doctrine\DBAL\LockMode,
Doctrine\ORM\Mapping\ClassMetadata,
Doctrine\ORM\Query,
- Doctrine\ORM\Query\QueryException;
+ Doctrine\ORM\Query\QueryException,
+ Doctrine\ORM\Mapping\ClassMetadataInfo;
/**
* The SqlWalker is a TreeWalker that walks over a DQL AST and constructs
@@ -1307,6 +1308,14 @@ public function walkGroupByClause($groupByClause)
$item->type = AST\PathExpression::TYPE_STATE_FIELD;
$sqlParts[] = $this->walkGroupByItem($item);
}
+
+ foreach ($this->_queryComponents[$groupByItem]['metadata']->associationMappings AS $mapping) {
+ if ($mapping['isOwningSide'] && $mapping['type'] & ClassMetadataInfo::TO_ONE) {
+ $item = new AST\PathExpression(AST\PathExpression::TYPE_SINGLE_VALUED_ASSOCIATION, $groupByItem, $mapping['fieldName']);
+ $item->type = AST\PathExpression::TYPE_SINGLE_VALUED_ASSOCIATION;
+ $sqlParts[] = $this->walkGroupByItem($item);
+ }
+ }
}
return ' GROUP BY ' . implode(', ', $sqlParts);
View
16 tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php
@@ -1317,6 +1317,22 @@ public function testSelectWithArithmeticExpressionBeforeField()
'SELECT d0_.id AS id0, +d0_.value AS sclr1 FROM DDC1474Entity d0_'
);
}
+
+ /**
+ * @group DDC-1430
+ */
+ public function testGroupByAllFieldsWhenObjectHasForeignKeys()
+ {
+ $this->assertSqlGeneration(
+ 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u GROUP BY u',
+ 'SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3 FROM cms_users c0_ GROUP BY c0_.id, c0_.status, c0_.username, c0_.name, c0_.email_id'
+ );
+
+ $this->assertSqlGeneration(
+ 'SELECT e FROM Doctrine\Tests\Models\CMS\CmsEmployee e GROUP BY e',
+ 'SELECT c0_.id AS id0, c0_.name AS name1 FROM cms_employees c0_ GROUP BY c0_.id, c0_.name, c0_.spouse_id'
+ );
+ }
}
Something went wrong with that request. Please try again.