Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to preload on an association by association basis #16

Open
minglecm opened this issue Sep 19, 2013 · 6 comments
Open

Ability to preload on an association by association basis #16

minglecm opened this issue Sep 19, 2013 · 6 comments

Comments

@minglecm
Copy link
Contributor

The ability to specify preloads on an association would be a good addition to Brainstem.

These preloads would only be added when a specific association is requested (via includes) instead of all the time in the case of custom_preload.

Behavior around preloading multiple times (IE globally preloading [:workspace] and then preloading workspace in an association) would need to be examined.

class StoryPresenter < Brainstem::Presenter
  presents "Story"

  # This will still be used to globally load associations on all models.
  def custom_preload(models, associations = [])
    ActiveRecord::Associations::Preloader.new(models, [:workspace]).run
  end

  def present(story)
    {
      :implicit_preload   => association(:story) # preloads story implicitly based on method name
      :explicit_preload   => association(:blah, :preloads => [:story]) # will use :story instead of :blah
      :explicit_preload2  => association(:json_name => "time", :preloads => [:line_items]) { |model| model }
      :empty_preload      => association(:json_name => "test") { |model| model } # doesn't preload anything
    }
  end
end
@juanca
Copy link
Contributor

juanca commented Apr 28, 2016

@bennapp Here's an existing issue with similarly-like goals.

A workaround for the always preloaded custom_preload is to only use the preloader when a particular association is requested (via the second actual parameter).

@minglecm
Copy link
Contributor Author

@juanca
lost

@cantino
Copy link
Contributor

cantino commented Apr 29, 2016

Don't forget the new preload directive in presenters too. It gets run when the presenter is used on a primary load or association, I believe.

@juanca
Copy link
Contributor

juanca commented Apr 29, 2016

Interesting. I'll look into that as well. 👍

@spoontstr
Copy link

who are all these ghosts back from the past ;)

On Fri, Apr 29, 2016 at 11:14 AM, Juan Carlos Medina <
[email protected]> wrote:

Interesting. I'll look into that as well. 👍


You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub
#16 (comment)

Tricia Spoonts
Director of User Experience
[email protected]

'Proud 2015 Gartner Cool Vendor'

@cantino
Copy link
Contributor

cantino commented Apr 29, 2016

Open Source lives eternal.
On Fri, Apr 29, 2016 at 12:11 PM Tricia Spoonts [email protected]
wrote:

who are all these ghosts back from the past ;)

On Fri, Apr 29, 2016 at 11:14 AM, Juan Carlos Medina <
[email protected]> wrote:

Interesting. I'll look into that as well. 👍


You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub
<#16 (comment)

Tricia Spoonts
Director of User Experience
[email protected]

'Proud 2015 Gartner Cool Vendor'


You are receiving this because you commented.
Reply to this email directly or view it on GitHub
#16 (comment)

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

No branches or pull requests

4 participants