Hi all I am using four models user, member, unit, society I have linked member, unit and society through member_property table user has one to one association with member while all other models have many to many association. How do I link user to member, and user to unit through member i wanted something like <%= @user.member.unit.unit_number %></p> Can someone guide how to achieve this -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
You want to use Nested Associations, which are covered here: http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html On Dec 1, 12:28 am, chandrakant jain <ckjai...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi all > > I am using four models user, member, unit, society > I have linked member, unit and society through member_property table > user has one to one association with member while all other models > have many to many association. > > How do I link user to member, and user to unit through member > > i wanted something like > > <%= @user.member.unit.unit_number %></p> > > Can someone guide how to achieve this-- 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.
thank you so much I will check on this On Dec 1, 8:34 pm, Adam <accon...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> You want to use Nested Associations, which are covered here: > > http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMet... > > On Dec 1, 12:28 am, chandrakant jain <ckjai...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > > > > Hi all > > > I am using four models user, member, unit, society > > I have linked member, unit and society through member_property table > > user has one to one association with member while all other models > > have many to many association. > > > How do I link user to member, and user to unit through member > > > i wanted something like > > > <%= @user.member.unit.unit_number %></p> > > > Can someone guide how to achieve this-- 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.