Skip to content
This repository has been archived by the owner on Jun 30, 2018. It is now read-only.

Proposal / potential PR: Support for custom load parameters #762

Open
fgrehm opened this issue Jun 19, 2013 · 5 comments
Open

Proposal / potential PR: Support for custom load parameters #762

fgrehm opened this issue Jun 19, 2013 · 5 comments

Comments

@fgrehm
Copy link

fgrehm commented Jun 19, 2013

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 :)

@karmi
Copy link
Owner

karmi commented Jun 21, 2013

@fgrehm Sounds like a nice idea, but could you please add a more fleshed out example?

@fgrehm
Copy link
Author

fgrehm commented Jun 21, 2013

@karmi sure, I'll get back to u on monday :)

@fgrehm
Copy link
Author

fgrehm commented Jun 26, 2013

@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

@karmi
Copy link
Owner

karmi commented Jun 26, 2013

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.

@fgrehm
Copy link
Author

fgrehm commented Jun 26, 2013

@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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants