how do I group by two columns and provide a sum of the grouped items
ruby-on-rails-3
Solution
Assuming an `Item` model, you can pass an array to the `group` method as follows:
Item.group(["manufacturer", "model"]).sum(:qty)
# => {["Planar", "PL2410W"]=>3, ["Planar", "PL3610D"]=>2, ["Sony", "MF-2002"]=>2}
Problem
I'm building an inventory database and it has 2 columns that I would like to group by (manufacturer and model). How would I group by these columns and provide a sum of the items group? For example: ``` Qty Manufacturer Model 1 Sony MF-2002 1 Sony MF-2002 1 Planar PL2410W 1 Planar PL2410W 1 Planar PL2410W 1 Planar PL3610D 1 Planar PL3610D ``` Result: ``` Qty Manufacturer Model 2 Sony MF-2002 3 Planar PL2410W 2 Planar PL3610D ```