ruby on rails - ActiveRecord query based on belongs_to association count -


i have user model has may scores

class user < activerecord::base   has_many :scores 

i want able query postgresql db return users have @ least 1 score.

user.where(scores.count >= 1) 

any idea on how accomplish without adding counter_cache?

a more rails-ish way

user.joins(:scores).where('scores.user_id > 0') 

also, think select count(*) return number of users, not user rows themselves, i'm not sure that.


Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -