Created
December 5, 2014 08:16
-
-
Save osiro/7389fad23f77222677e6 to your computer and use it in GitHub Desktop.
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
heaps_of_users_wishlists = UsersWishlist.where(user: user) | |
heaps_of_groups = BookIdentifierGroup.where(id: heaps_of_users_wishlists.pluck(:book_identifier_group_id) | |
the_book_identifiers_I_wanna = BookIdentifier.where(group_id: heaps_of_groups.pluck(:id)) | |
puts the_book_identifiers_I_wanna | |
# This shit triggers 3 queries | |
heaps_of_users_wishlists = UsersWishlist.where(user: user) | |
heaps_of_groups = BookIdentifierGroup.joins(:users_wishlists).merge(heaps_of_users_wishlists) | |
the_book_identifiers_I_wanna = BookIdentifier.joins(:group).merge(heaps_of_groups) | |
# And this shit triggers 1 query |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment