biagidp
biagidp

Reputation: 2185

Searching on associations in Spree

Spree reports utilize ransack for searching. According to the ransack documentation I should be able to use the following line of code to search for all the orders with line items containing more than one item.

Spree::Order.ransack(line_items_quantity_gt: 1)

But when I enter that line in the console I get the following output

Ransack::Search<class: Spree::Order, base: Grouping <combinator: and>>

According to the ransack documentation that should work. The association doesn't appear to be accepted in the search parameters. Line items is in the list provided by Spree::Order.ransackable_associations so I'm a little confused as to why this isn't working.

Upvotes: 1

Views: 563

Answers (1)

oklas
oklas

Reputation: 8220

Some associations (attributes, scopes) my be whitelisted, others are ignored by ransack.

To override defaults in app add (to) file app/controllers/spree/products_controller_decorator.rb:

Spree::ProductsController.class_eval do

  Spree::Product.whitelisted_ransackable_associations = %w[taxons stores variants_including_master master variants]

end

Upvotes: 0

Related Questions