Topic: help to get value from an array of objects
I got an array with lot of objects (type 'Product') like this (only 4 here) :
[#<Product id: 295147, company_id: 1>, #<Product id: 303667, company_id: 2>, #<Product id: 279561, company_id: 9>, #<Product id: 289477, company_id: 4>]
What I want to do is iterate on the array and for each company_id, know how much products have the same company_id.
I get the company_id like this : products.collect(&:company_id).uniq
but after I don't know how to get an array like this : [1 => 22, 2 =>15, 3 => 9]
Thanks for your help