forked from drapergem/draper
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Associations:
#decorate
queries DB every time
`ActiveRecord::Associations::CollectionProxy#decorate` ignores `target` (be it already loaded or not) and loads the association again every time it's called. That's why unsaved records get missing from the decorated collection. Resolves drapergem#646, drapergem#706, drapergem#827.
- Loading branch information
1 parent
7093384
commit ff5061e
Showing
2 changed files
with
22 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module Draper | ||
module Decoratable | ||
module CollectionProxy | ||
# Decorates a collection of objects. Used at the end of a scope chain. | ||
# | ||
# @example | ||
# company.products.popular.decorate | ||
# @param [Hash] options | ||
# see {Decorator.decorate_collection}. | ||
def decorate(options = {}) | ||
decorator_class.decorate_collection(load_target, options.reverse_merge(with: nil)) | ||
end | ||
end | ||
end | ||
end |