I’m trying to retrieve all the users ids who have their preferences (IN (1,7) AND (2)). Even without the group on user_id. It doesn’t work. Any idea would be very helpful.
HasPreference.find(:all, :conditions => ["preference_id IN (1,7) AND preference_id = 2"], :group => :user_id)
TABLE is ‘has_preferences’
ID -- PREFERENCE_ID -- USER_ID
1 -- 2 -- 1
1 -- 7 -- 1
1 -- 1 -- 1
1 -- 2 -- 2
I’d like to get [1] as a result.
Thanks
Create an index on
(preference_id, user_id)for this to work fast.