When trying to perform relational division using Doctrine 1.2, I receive a "Duplicate alias" error over what seems like the DISTINCT found in the query below:
SELECT
Data.ID
FROM
Data
INNER JOIN
TaggedData ON (Data.id = TaggedData.data_id)
INNER JOIN
Tag ON (Tag.id = TaggedData.tag_id)
WHERE
Tag.id IN ('1' , '2')
HAVING COUNT(DISTINCT tag.iD)=2
If I remove DISTINCT from the query, it runs but doesn't get me what I want. Is there a proper way to get Doctrine past this issue?
Specific code:
$query = $this->createQuery("p")
->select("p.*")
->innerJoin("p.Data s")
->innerJoin("s.Tags c")
;
$query
->andWhereIn("c.id", $tags)
->addHaving("COUNT(DISTINCT c.id) = ?", count($tags))
;