Skip to content

Instantly share code, notes, and snippets.

@fizzwu
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fizzwu/34d10c90537f6b4c6f5b to your computer and use it in GitHub Desktop.
Save fizzwu/34d10c90537f6b4c6f5b to your computer and use it in GitHub Desktop.
preload associations with find_by_sql
# 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