I want to make this sql query in doctrine:
SELECT *
FROM (
(SELECT *, e1.stop_date as sort_date FROM `event` e1 WHERE ...)
UNION
(SELECT *, e2.start_date as sort_date FROM `event` e2 WHERE ...)
) e3
ORDER BY e3.sort_date
And I want to result of symfony model connected to the event table, like using:
Doctrine_Core::getTable('Event')->createQuery('e')
Any ideas?
You can try Doctrine’s DQL languaje for complex queries:
http://doctrine.readthedocs.org/en/latest/en/manual/dql-doctrine-query-language.html#subqueries
Or, alternatively, you can create a View in your database and use it as source table for simpler Doctrine queries.
I’ve used both approachs in my projects and worked well, it depends on the way you access data, if you need to update, if you are allowed to create views, etc.