Last active
January 27, 2019 21:21
-
-
Save Bajena/e80d3b6293490d02fe68c9a28c67fa04 to your computer and use it in GitHub Desktop.
N+1 zapytań - przykład
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
posts = Post.where(id: [1, 2, 3]) | |
# SELECT * FROM posts WHERE id IN (1, 2, 3) | |
users = posts.map { |post| post.user } | |
# SELECT * FROM users WHERE id = 1 | |
# SELECT * FROM users WHERE id = 2 | |
# SELECT * FROM users WHERE id = 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment