Hofstadter Hofstadter - 1 year ago 405
SQL Question

SQL query with UNION in Doctrine Symfony

I have a question about the translation of a SQL query in Doctrine Symfony. I would like to do a thing like that :

FROM member m
SELECT id_member
FROM friend
WHERE id_friend=99
SELECT id_friend
FROM friend
WHERE id_member=99
) a ON m.id=a.id_member
WHERE m.visible=1

In this example, i search all friends of the user 99.

My tables :

Member: (id, name, visible)

Friend: (id, id_member,
id_friend, active)

Precision : I would like to use the Symfony pager.

A solution ? Thank you !

Answer Source

UNION is not supported within DQL, but you can issue your query using RAW SQL ->

$q = Doctrine_Manager::getInstance()->getCurrentConnection();
$result = $q->execute(" -- RAW SQL HERE -- ");