Details
Description
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 entities:
- Article(id primary key, title, content)
- ArticleTag(article_id, tag, primary key (article_id, tag))
Example DQL: select art from Article art where exists (select tag from ArticleTag tag where tag.article = art)
Verified:
/** * @group DDC-1435 */ public function testForeignKeyAsPrimaryKeySubselect() { $this->assertSqlGeneration( "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 .."