You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Similar to #932 for associations, calling `#decorate` on a relation
loads the records every time, regardless of whether the underlying
relation has already been loaded.
This is because the default of passing `all` as the collection to
decorate ends up being a new relation, so even if it were previously
loaded, the new relation including `all` needs to be loaded.
`ActiveRecord::Associations::CollectionProxy` actually inherits from
`ActiveRecord::Relation`, so by pushing this up to the relation, we can
cover both scenarios.
https://github.com/rails/rails/blob/57c24948eb5cc9e5f9a4cecb6f2060f53e2246e1/activerecord/lib/active_record/associations/collection_proxy.rb#L31
The documentation included in #932 (`company.products.popular.decorate`)
wasn't correct as you're decorating a relation there (`popular`), not
just the association (`products`).
This now covers the association itself (`company.products.decorate`), as
well as a relation from that association (`company.products.popular.decorate`),
as well as a relation right from the class without associations
(`Product.popular.decorate`).
Decorating the class itself (`Product.decorate`) still calls `all` since
the model class is not a relation itself.
0 commit comments