Last active
August 29, 2015 14:06
-
-
Save fizzwu/34d10c90537f6b4c6f5b to your computer and use it in GitHub Desktop.
preload associations with find_by_sql
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
# http://cha1tanya.com/2013/10/26/preload-associations-with-find-by-sql.html | |
# Rails4 way | |
@users = User.find_by_sql(some_condition) | |
ActiveRecord::Associations::Preloader.new.preload(@users, :company) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment