I have these three models:
class Order
has_many :items
end
class Item
belongs_to :order
belongs_to :product
end
class Product
has_many :orders, through: :items
has_many :items
end
And I need to make a list of how many of each product are in the orders from a given date range.
I have a scope to get all orders in a date range:
Order.date_range(from, to)
Now I need to group and count; there are product_id
and units
fields on the item model.
I have seen solutions but just in cases with two tables (order>product) but not with three (order>item>product).