mxrgus pxrt
2010-Mar-26 11:16 UTC
Many-to-many relationship to table itself through other table
Hello, I would like to have many-to-many relationship to object itself with additional info, but I did not find any info on that, could someone suggest something? Example: Service -- name -- description ServiceConnection -- type -- description -- parent_id -- child_id -- 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.
Colin Law
2010-Mar-26 16:58 UTC
Re: Many-to-many relationship to table itself through other table
On 26 March 2010 11:16, mxrgus pxrt <margus.part-kl/E61UDngg@public.gmane.org> wrote:> Hello, > > I would like to have many-to-many relationship to object itself with > additional info, but I did not find any info on that, could someone > suggest something? > > Example: > > > Service > -- name > -- description > > ServiceConnection > -- type > -- description > -- parent_id > -- child_idHave a look at has_many :through with class_name and foreign_key. You will need two of these, one for parents and one for children. has_many :service_connections has_many :parents, :through => :service_connection, :class_name..... etc has_many :children, :through => :service_connection, :class_name..... etc The rails guide on activerecord associations at http://guides.rubyonrails.org/ should help. 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Rutvij Pandya
2010-Mar-26 19:15 UTC
Re: Many-to-many relationship to table itself through other table
mxrgus pxrt wrote:> Hello, > > I would like to have many-to-many relationship to object itself with > additional info, but I did not find any info on that, could someone > suggest something? > > Example: > > > Service > -- name > -- description > > ServiceConnection > -- type > -- description > -- parent_id > -- child_id-------------------------------------------- Refer link given below.. http://www.noupe.com/ror/a-simple-twitter-app-with-ruby-on-rails-building-friendships.html -- 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-/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.