mardi 13 octobre 2015

How to search Spree::Orders and associations with ransack gem

Using Spree and ransack, how is it possible to return the Spree::Variants included in Spree::Orders that have completed since a certain date? The ransack documentation gives a little advice about searching associations, but does not seem to go deep enough.

Spree::Order
  has_many :line_items

Spree::LineItem
  belongs_to :line_item
  belongs_to :variant 

Spree::Variant
  has_many: line_items

Orders that have completed can be searched with:

  o=Spree::Order.complete.ransack(completed_at_gt: '2015-05-01')

But how to find the Spree::LineItems within these orders and return the Spree::Variants' SKUs within these orders is unclear.

Aucun commentaire:

Enregistrer un commentaire