Created
November 24, 2016 10:39
-
-
Save begin29/4dc0af5415e458c6c49f7b9f3851d09b to your computer and use it in GitHub Desktop.
includes, preload, eager_loading
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
# :includes delegates to :eager_loading or :preload | |
# :eager_loading - one big query | |
# :preload - few small queries | |
# get only polish adresses then preload all | |
User.joins(:addresses).where("addresses.country = ?", "Poland").preload(:addresses) | |
# SELECT "users".* FROM "users" | |
# INNER JOIN "addresses" ON "addresses"."user_id" = "users"."id" | |
# WHERE (addresses.country = 'Poland') | |
# SELECT "addresses".* FROM "addresses" WHERE "addresses"."user_id" IN (1) | |
# get only polish adresses | |
User.joins(:addresses).where("addresses.country = ?", "Poland").includes(:addresses) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment