I'am confused when I try to count the total votes in my votes table in rails..
serviceproviders has_many votes
votes belongs_to serviceproviders
I tried like this :
sp = Serviceprovider.joins(:votes).group_by(&:id).count
but it doesn't get the right output.
example output I want is:
If in the table Jhon Doe has 5 row of votes in the table, I can get the total 5 votes when I query. Can any give me the idea how can execute the query. Thank you!
Update:
Thank you for those answers.
I tried this in my rails c.
vote = Vote.joins(:serviceprovider).group(:serviceprovider_id).count
and I got the results: {108=>2, 109=>1}
My question how can I get the top 10 highest votes?