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

php - get table cell data from and place a copy in another table -

javascript - Mootools wait with Fx.Morph start -

php - Navigate throught databse rows -