I am trying to make an admin dashboard that shows an administrator relevant statistics about the site. For example, given a company has many users, finding the average number of users per company, or the maximum number of users a company has.
I have found activerecord::calculations, which seems to do most of what I want, but as far as I can tell, it doesn’t let you do anything with relations. How would I go about finding counts or averages that are grouped by relations?
You have to think of it in terms of the User.
The simplest way would be
But then you’ll have to load the Companies and match them up.
Then you could try and do