views:

43

answers:

1

Hi How can I add multiple objects in a find condition? I created a table for comment 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 users 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 If tried this with no luck

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

Any advice?

+1  A: 

Try this:

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

Same as:

Comment.all(:conditions => {:profile_id => [user.friends, user].flatten})
KandadaBoggu
Awesome! Thank you!
brian
@brian: If you accept an answer, please also give it an up vote.
Lars Haugseth