Reputation: 391
I'm trying to create a custom report and I want to pull in all completed orders for a specific state.
Something like:
orders = Spree::Order.complete.for_state("Utah")
How would I do this?
The part that confuses me is the fact that the state is a 3 part assocoation.
Order has_one ship_address, which is an Address instance, which then belongs_to State.
Upvotes: 0
Views: 225
Reputation: 9691
Try this:
Spree::Order.complete.joins(:bill_address).where("state_name = 'Utah'")
Spree::Order.complete.joins(:ship_address).where("state_name = 'Utah'")
Depending on which one you are looking for.
Upvotes: 2