Wednesday, June 24, 2015

Rails - how to preload scopes

http://www.justinweiss.com/blog/2015/06/23/how-to-preload-rails-scopes

It seems Scopes can result in N+1 queries if not used properly since they cannot be preloaded...And author shows a way of how to use them correctly (i.e. without resulting in N+1 queries).

To learn about eager loading - http://guides.rubyonrails.org/active_record_querying.html#eager-loading-associations

More on the topic:

Preload, Eagerload, Includes and Joins - 

http://blog.bigbinary.com/2013/07/01/preload-vs-eager-load-vs-joins-vs-includes.html

No comments:

Post a Comment

Followers

Blog Archive