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
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---