On 22 January 2010 21:24, palidanx
<dan.quach-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> Hi everyone,
>
> I have a model like the following
> User.id
>
> Friends
> invited (fk to user)
> inviter (fk to user)
>
> Now, what I would like to do is given a uid, retrieve all the users
> related to the inviter. So a retarded way of oding hti sis..
>
> friendRequests = Friend.find(:all, :conditions => {:invited_id =>
> uid})
>
> Then iterate through the friend requests, grabbing each user object..
>
> I know there is a better way of doing this in one query.. can I have
> some direction on doing this?
I don''t understand fully the associations between the models, how have
you setup the has_many, belongs_to etc.
Can you be more explicit about what you mean by ''all the users related
to the inviter''?
Colin
--
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.