Created
April 21, 2011 19:20
-
-
Save scottwater/935283 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Site.joins(:user).select('sites.user_id, count(*) as count').group('sites.user_id') | |
<Site user_id: 1> #should have a count of 2 | |
# returns only the user_id. If I cheat and name the 'count' column the same name as another column on my model it returned. | |
Site.joins(:user).select('sites.user_id, count(*) as id').group('sites.user_id') #BAD! | |
<Site id: 2, user_id: 1> #id == count in this result |
Hi Kevin,
That was the trick.
Thanks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Each returned object should have a count attribute with the count assigned.
Testing locally: