Last active
August 29, 2015 13:56
-
-
Save jpowers/9278638 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #return the total number of user_contents for a profile | |
| def self.include_content_count | |
| select('profiles.*, (select count(*) from user_contents where user_contents.profile_id = profiles.id) as user_content_count') | |
| end | |
| #limit the results by user_contents total for a profile | |
| #also call include_content_count to get the count | |
| def self.has_min_content_count(total=1) | |
| include_content_count | |
| .where('(select count(*) as total from user_contents where user_contents.profile_id = profiles.id) > ?', total) | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment