Query Help


#1

In my App …i have Userinfo and FriendsInfo table.Each user has many
friends.those friends are user of the app.
for example i have 3 users in my userinfo table.namely
=>John
=>Victor
=>Masvi

the users can add other users as friends.the user john has friends as
victor and masvi.these information i have stored in my FriendsInfo
table.
friendstable structure
id user_id friend_id
1 1 2
1 1 3

if i want to find who are friends of the john…
i do query like this @friends = Userinfo.find(:all,:conditions =>
{:user_id => params[user_id]})
so i will be getting all the friends id of john(his id is 1)
the @friends result set is array.
if i want display the friends name of john means
i do query like this
@friends_name = Array.new
@friends.each do |f|
@name = Userinfo.find_by_id(f.friend_id)
@friends_name << @name
end

how can i optimise my queries to get the above friends name…

pls help