You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a User, which has_many :posts. I'd love to have a column that showed the # of posts, so I could sort my Users by the ones with the most posts. Is this possible?
The text was updated successfully, but these errors were encountered:
I can do this manually, with Postgres support, by running:
@users = User.select("(select COUNT(posts.id) from posts where posts.user_id = users.id)
AS posts_count, users.#{User.column_names.join(",users.")}").
order("posts_count DESC").limit(30)
I have a User, which has_many :posts. I'd love to have a column that showed the # of posts, so I could sort my Users by the ones with the most posts. Is this possible?
The text was updated successfully, but these errors were encountered: