I have a join table that I'm using to find available services for an order form; in that table is the utility_id
and a company_id
.
What I want is a group (hash) where the keys are the utility names and the values are hashes of the corresponding companies.
I got the following...
Service.find(:all).to_set.classify { |service| Utility.find(service.utility_id).name }
... which very nicely gives me a hash where the keys are the utility names, but the values are Sets of the Service records, not just the company names (I don't need the actual records), and I can't figure out how I'd make the hash I want:
# example of what I would like to have
{"electricity" => {"conEd" => 1, "Dominian" => 2}, "gas" => {"conEd" => 1}}
# where the key is Utility.name, and the value-hash is {Company.name => Company.id}
How would I do this?