(written by lawrence krubner, however indented passages are often quotes). You can contact lawrence at: lawrence@krubner.com

I’m adding a new page to WP Questions to show “Good Citizens”, that is, experts who vote. You can see the query I wrote below. I wrote this and it occurred to me there is no ORM in PHP that could handle this. The site is built using Symfony and Propel, but I would not want to handle this with Propel.

SELECT count(vote) as voteTotal, sf_guard_user.*, sf_guard_user_profile.*, question.subject
FROM vote
JOIN sf_guard_user on vote.user_id_casting_vote=sf_guard_user.id
JOIN sf_guard_user_profile on sf_guard_user.id=sf_guard_user_profile.user_id
AND sf_guard_user_profile.user_id=vote.user_id_casting_vote
LEFT JOIN question on vote.question_id = question.id
WHERE vote.user_id_casting_vote != question.user_id
AND sf_guard_user.is_super_admin != 1
AND vote.created_at > ‘$oneMonthAgo’
GROUP BY vote.user_id_casting_vote
HAVING voteTotal > 2
ORDER BY voteTotal desc