Query problem

Hi,
I am using postgres sql.
I am writing following query to get the user friends.
The query is working fine.

“User.fnd (:all,:joins => “INNER JOIN friendship_requests fr on
(users.id = fr.friendship_target_id or users.id= fr.user_id)”,
:conditions => [’(fr.user_id = ? or fr.friendship_target_id= ?) and
users.id != ? AND fr.status = ?’, self.id,self.id, self.id,
‘accepted’])”

The query only returns me the user object, but I want the
friendship_requests object as well.

Can anyone tell how should I modify this query so that I will get the
both users as well as friendship_requests object.

Thanks,
Tushar

You should avoid using big chunks of sql like this. You haven’t
specified your schema, and i’m afraid i don’t feel like reverse
engineering your sql at the moment to work out what you’re trying to do.

If you use the :find option instead of :joins you can write something a
bit nicer like this

@users = User.find(:all, :include => [:friendship_requests])

Then in your view you can iterate over the friendship requests for each
user. Or whatever, like i say with no explanation of what you’re trying
to do it’s hard to advise clearly.