Skip to content

Instantly share code, notes, and snippets.

@jpowers
Last active August 29, 2015 13:56
Show Gist options
  • Select an option

  • Save jpowers/9278638 to your computer and use it in GitHub Desktop.

Select an option

Save jpowers/9278638 to your computer and use it in GitHub Desktop.
#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