views:

18

answers:

1

Say I have the following in my console:

@user.favcolors
=> [#<FavColors id: 1, color_id: 18, fav_id: 1>,
    #<FavColors id: 2, color_id: 19, fav_id: 1>]
@user.favcolors.count
=> 2

However, since fav_id is same in both results (1). I want this count to be 1, instead of 2.

Is there a way I can put where clause in the code @user.favcolors?

A: 
@user.favcolors.find(:all, :group => 'favcolours.fav_id')
mark
`@user.favcolors.find(:all, :select => 'DISTINCT favcolors.fav_id').count` worked for me. thanks for telling me that find can be called on the association.
Omnipresent