I am using Rails 2.3.5 .
This is a standard case. Tables are: users, comments, user_comments . I need to find all the users who have status 'active' and have posted at least one comment.
I know comments table can have foreign key but this is a contrived example. There are two users in the table. There are two comments. Both the comments are posted by the first user.
named_scope :with_atleast_one_comment, lambda { {
:joins => 'inner join user_comments on users.id = user_comments.user_id ' } }
named_scope :with_active_status, {:conditions => {:status => 'active'} }
When I execute
User.with_atleast_one_comment.with_active_status
I get two records. Since both the comments are posted by one user I want only one user.
What's the fix?