Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
The bad
last_post_ids = []
User.where(id: Post.all.distinct.pluck(:user_id)).find_each |user|
last_post_ids << user.posts.order(created_at: :desc).limit(1).pluck(:id).last
end
last_posts = Post.where(id: last_post_ids).order(created_at: :desc)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.