Details
-
Type:
Improvement
-
Status:
Reopened
-
Priority:
Minor
-
Resolution: Unresolved
-
Affects Version/s: 2.0
-
Fix Version/s: None
-
Component/s: ORM
-
Security Level: All
-
Labels:None
Description
With the schema:
Image
@Id
$id
Tag
@Id
$Id
Tag_Image
@Id
@OneToOne(targetEntity="Tag")
@JoinColumn(name="tag")
$tag
@Id
@OneToOne(targetEntity="Image")
@JoinColumn(name="image")
$image
Given the following DQL,
SELECT img
FROM Image
LEFT JOIN img.tags tag
WHERE tag.id=:tag
Doctrine Generates this SQL
SELECT i0_.id AS id1
FROM Image i0_
LEFT JOIN Tag_Image t2_
ON i0_.id = t2_.image
LEFT JOIN Tag t1_
ON t1_.id = t2_.tag
WHERE t1_.id = 37
Which unncessarily joins against Tag, given that the foreign key Tag.id is also found in Tag_Image.tag.
This is not a bug, but expected behavior.
You can select against the alias if its on the owning side of the association:
In this case it is not a left join though, if you want a left join you HAVE to join.