|
|
|
|
|
by smw
23 days ago
|
|
Even the 'worst' of the ORMs (according to the people in these threads) makes this very easy: users = User.find_by_sql(<<~SQL)
SELECT users.*,
COUNT(posts.id) AS posts_count
FROM users
LEFT JOIN posts ON posts.user_id = users.id
GROUP BY users.id
HAVING COUNT(posts.id) > 10
SQL
users.first.posts_count
# => 17
|
|