I need to preload associations of the model with complex conditions. NO, includes
doesn't work for me. It generate wrong SQL for my task.
I take a look to the ActiveRecord::Associations::Preloader
and find that he take an preload_scope
argument:
http://apidock.com/rails/v4.2.1/ActiveRecord/Associations/Preloader/preload
def preload(records, associations, preload_scope = nil)
# ...
end
But I can't find any example using it. What is preload_scope
in this case? And how I can use it for filtering associations?
Thanks!
User Load (12.1ms) SELECT "users".* FROM "users" WHERE (created_at > '2015-01-01') AND "users"."cat" IN (52, 50, 51, 53) User Load (1.2ms) SELECT "users".* FROM "users" WHERE (created_at > '2015-01-01') User Load (5.1ms) SELECT "users".* FROM "users"
– Mountaintop