如何在Doctrine 2.0中編寫這個SQL查詢(並獲取結果)?如何在Doctrine 2.0中編寫UNION
(SELECT 'group' AS type, CONCAT(u.firstname, " ", u.surname) as fullname, g.name AS subject, user_id, who_id, group_id AS subject_id, created FROM group_notification JOIN users u ON(who_id = u.id) JOIN groups g ON(group_id = g.id))
UNION
(SELECT 'event' AS type, CONCAT(u.firstname, " ", u.surname) as fullname, e.name AS subject, user_id, who_id, event_id AS subject_id, created FROM event_notification JOIN users u ON(who_id = u.id) JOIN events e ON(event_id = e.id))
ORDER BY created
該解決方案的解釋如何? – ihsan 2014-12-25 01:04:42
@ihsan你可以從基類庫('Notification')中選擇,並且你可以得到子類型的所有對象('NotificationGroup','NotificationEvent',甚至只是'Notification',如果你還沒有聲明它是抽象的)。如果你只需要某些類型,那麼你可以在WHERE中使用'INSTANCE OF'運算符。 – 2016-02-04 12:44:43