Jira issue originally created by user phekmat:
If an entity has a foreign key as part of its primary key and you try to query that entity in a subselect clause in DQL, an exception is thrown in ClassMetadataInfo->getQuotedColumnName. The problem seems to be that it's only considering the field mappings rather than both the field and association mappings when it's looking for the correct column name.
Example DQL: select art from Article art where exists (select tag from ArticleTag tag where tag.article = art)
Comment created by @beberlei:
* @group [DDC-1435](http://www.doctrine-project.org/jira/browse/DDC-1435)
public function testForeignKeyAsPrimaryKeySubselect()
"SELECT s FROM Doctrine\Tests\Models\DDC117\DDC117Article s WHERE EXISTS (SELECT r FROM Doctrine\Tests\Models\DDC117\DDC117Reference r WHERE r.source = s)",
This however is not possible anyways, since you cannot have "r" in a SimpleSelectExpression when it resolves to multiple columns. You can try to select just one arbitrary field, for example."SELECT r.foobar FROM .."
Comment created by phekmat:
Would that just be a documentation issue then? I didn't see that restriction in the grammar, but I may have overlooked it. I issued a pull request for this issue assuming that an association mapped field is valid input for getQuotedColumnName.
Selecting a single field does work fine.
Did you touch this in your latest changes to SimpleSelectExpression guilherme?
Comment created by @guilhermeblanco:
@beberlei No. Issue was totally unrelated.
Please merge my commit to 2.1.X.
The issue was caused by the identifier iteration was considering that @Id fields are always fields, never associations. You may see that in method getQuoteColumnName.
Solution was to create a new method called getQuotedIdenitiferColumnNames and consume it in SqlWalker.
This addresses the issue.
Committed patch and test case as of: 0ec2cc5
Issue was closed with resolution "Fixed"
Merged into 2.1.x
This issue is referenced in Github Pull-Request GH-159
A related Github Pull-Request [GH-159] was opened