Ecl1pse Armageddon
Ecl1pse Armageddon

Reputation: 391

In Spree admin how could I pull in all orders completed for a state?

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

Answers (1)

Benjamin Tan Wei Hao
Benjamin Tan Wei Hao

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

Related Questions