-
Notifications
You must be signed in to change notification settings - Fork 15
Open
Description
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
Metadata
Metadata
Assignees
Labels
No labels