SELECT p FROM Post p JOIN p.postTags pt JOIN pt.tag t WHERE t.name = :name
Don't forget to make sure Post
has one-to-many with PostTag
.
题
I have this very usual question. but I spent a lot of time cannot solve. I am using symfony2 with doctrine. any help? appreciate
let say I have 3 entities: Post, Tag, PostTag
I need to do a Post listing filter by Tag.
SELECT p,pt FROM PostTag pt LEFT JOIN pt.post p
this result duplicated posts due to a Post has many PostTags.
any solution please advice
解决方案
SELECT p FROM Post p JOIN p.postTags pt JOIN pt.tag t WHERE t.name = :name
Don't forget to make sure Post
has one-to-many with PostTag
.