Im using symfony 2 and doctrine. I have 4 entities, CustomPage, Tag, CustomPageTag, Comment.
Every CustomPage can have many tags, and many comments. I want to select a customPage (with all comments) wich have some specific tags.
Example: I want to select the customPage with 'tag1' AND 'tag2'
i did this,
SELECT CUSTOMPAGE, TAG, CUSTOMPAGE_TAG, COMMENT FROM CustomBundle:CustomPage CUSTOMPAGE JOIN CUSTOMPAGE.comments COMMENT JOIN CUSTOMPAGE.tags CUSTOMPAGE_TAG JOIN CUSTOMPAGE_TAG.tag TAG WHERE TAG.name IN ('tag1','tag2') GROUP BY CUSTOMPAGE.id HAVING COUNT(DISTINCT CUSTOMPAGE_TAG.name) = 2
It works well, but the problem is that it return only one comment (i want it all).