Proposal / potential PR: Support for custom load parameters
Hey @karmi,
I've just started experimenting with the code below and I was wondering if it is something that could be added to Tire's core or to tire-contrib:
Tire::Results::Collection.class_eval do
def __find_records_by_ids(klass, ids)
if @options[:load].is_a?(Hash)
klass.find(ids, @options[:load][klass])
else
@options[:load] === true ? klass.find(ids) : klass.find(ids, @options[:load])
end
end
end
The idea would be to support fine grained eager loading on multi model searches. If you think it is a nice idea, I'd be more than happy to turn this issue into a proper pull request either here or on tire-contrib :)
@fgrehm Sounds like a nice idea, but could you please add a more fleshed out example?
@karmi sure, I'll get back to u on monday :)
@karmi here's a simple gist with example models and usage, this is basically what I'm currently doing on the app I'm working on. I hope they are self explanatory but if u need more info just LMK :) our current need is to perform a global / multi model search and render associations data on the search results page alongside each result item so we ended up doing that to avoid N+1 queries
Will have a look. At the moment, the biggest problem is related to #767, and with the current release of Rails 4, the problem is more imminent.
@karmi got it, but the issues are not mutually exclusive as there's currently no way to specify custom eager loading behavior per class on multi model searches :) I've updated the gist adding an example of how it could be used with lambdas