1

How can I add multiple objects in a find condition? I created a table for comments but I want to display comments posted by a user and his or her friends. I got the find method to return a list of comments by a user's friends but I cannot get the 'find' method to include the user as well.

For example:

User = profile.find(1)
Comment.find(:all, :conditions => {:profile_id => user.friends})

This works great but I also need to have the current user in the list of comments as well. I tried this with no luck:

Comment.find(:all, :conditions => {:profile_id => [user, user.friends]})

Any advice?

1 Answer 1

2

Try this:

Comment.find_all_by_profile_id([user.friends, user].flatten)

Same as:

Comment.all(:conditions => {:profile_id => [user.friends, user].flatten})
Sign up to request clarification or add additional context in comments.

1 Comment

@brian: If you accept an answer, please also give it an up vote.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.