I have 2 models
Category
- id
- name
and
Transaction
- id
- category_id
- amount
I want to find the sum of all transactions for each category.
I know I can get a list of caterogies and then get the sum for all the transactions with the category_id but it will do 20+ queries.
Is there a way to do it all in one query?
Edit: I want to end up with a list of [[category1, sum], [category2, sum]].
This will return a hash similar to this:
or
To get the actual
Categorynames: