Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Rails includes
posts = Post.where(id: [1, 2, 3]).includes(:user)
# SELECT * FROM posts WHERE id IN (1, 2, 3)
# SELECT * FROM users WHERE id IN (1, 2, 3)
users = posts.map { |post| post.user }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment