Cách viết truy vấn SQL này trong Doctrine 2.0 (và tìm nạp kết quả)?Cách viết UNION trong Doctrine 2.0
(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
Và giải thích cho giải pháp này như thế nào? – ihsan
@ihsan bạn chọn từ kho lưu trữ lớp cơ sở ('Notification') và bạn nhận được tất cả các đối tượng có loại phân lớp (' NotificationGroup', 'NotificationEvent', và thậm chí chỉ là' Notification' nếu bạn chưa khai báo nó trừu tượng). Nếu bạn chỉ cần một số loại nhất định, thì bạn có thể sử dụng toán tử 'INSTANCE OF' trong WHERE. –