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
Given: Creation of a Decorator::Collection instance with a context and calling order on that collection to pass database sort ordering through to the ActiveRecord::Association Expected: The resulting collection should preserve the original context Actual: It does not preserve the context.
Example code:
classPosts < ActiveRecord::BaseendclassPostDecorator < Draper::Decoratorenddecorated_collection=PostDecorator.decorate_collection(Post.all,context: {user: "foo"})decorated_collection.context == {user: "foo"}# truedecorated_collection=decorated_collection.order("created_at asc")decorated_collection.context == {user: "foo"}# false, but should be true
I don't know if this is the proper long term fix for this, but this fix works in Draper::QueryMethods:
Discovered a workaround until this is fixed which is to use a similar approach to adding Pagination support. In the application specific collection decorator class, you can add the order method and simply tack on the context after calling super
classApplicationDecorator < Draper::Decoratordefself.collection_decorator_classPaginatingDecoratorendendclassPaginatingDecorator < Draper::CollectionDecorator# support for will_paginatedelegate:current_page,:total_entries,:total_pages,:per_page,:offsetdeforder(*args)collection=supercollection.context=self.contextcollectionenddefpaginate(*args)object.paginate(*args).decorate(context: self.context)endend
Given: Creation of a Decorator::Collection instance with a context and calling
order
on that collection to pass database sort ordering through to the ActiveRecord::AssociationExpected: The resulting collection should preserve the original context
Actual: It does not preserve the context.
Example code:
I don't know if this is the proper long term fix for this, but this fix works in Draper::QueryMethods:
draper/lib/draper/query_methods.rb
Lines 6 to 10 in dd32a4a
to:
The text was updated successfully, but these errors were encountered: