What is the equivelant of the following SQL in rails:
SELECT person, count(person) as occurance FROM invoice GROUP BY person;
This would give something like:
Person | Occurance
Bill 1
Joe 15
Carlos 7
etc etc…
It seems the fx. Person.count(…) will only yield the actual occurance,
but not listed with the actual person - and Person.find(…) will not
give the occurance. So is my only option to use find_by_sql() ?
It seems the fx. Person.count(…) will only yield the actual occurance,
but not listed with the actual person - and Person.find(…) will not
give the occurance. So is my only option to use find_by_sql() ?
How about (if I’m getting the table relations right):
Invoice.find(:all, :select => “person, count(person) as occurrence”,
:group => “person”)