Hi, I have such a data base which has a self-join as association. I want to know that is there any good gem available which i can use for self-join in my application? My main intension is to prevent infinite loop in searching the records. @Anand -- 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.
On Fri, Aug 26, 2011 at 7:31 PM, News Aanad <news.anand11-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, I have such a data base which has a self-join as association. > I want to know that is there any good gem available which i can use for > self-join in my application? > My main intension is to prevent infinite loop in searching the records. > >How are you going to get an infinite loop while searching? Having class User < ActiveRecord::Base belongs_to :another_user, :class_name => ''User'' end and eager loading another_user would not result in an infinite loop.> @Anand > > -- > 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. >-- ------------------------------------------------------------- visit my blog at http://jimlabs.heroku.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.
News Aanad wrote in post #1018617:> Hi, I have such a data base which has a self-join as association. > I want to know that is there any good gem available which i can use for > self-join in my application? > My main intension is to prevent infinite loop in searching the records.I don''t know of any gem that provides this type of validation, but I have in the past written the validation myself. In my case the self-join was used to describe a bill-of-material. Imagine you have the following structure: # Product (P) # Component Part (C) # Assembly (A) P1 \_ C1 |_ A1 \_ C2 |_ C3 |_ A2 \_ C3 |_ C4 |_ A1 <------- A2 can never be build \_ C2 |_ C3 |_ A2 \_ C3 |_ C4 |_ A1 \_ <------ This tree grows to infinity Validating this involves recursively checking every sub-tree to make sure that they do not contain any non-leaf node in the ancestry. Starting from the root (P1) you would have to check the entire tree to make sure that P1 never appears anywhere in tree. Then move to the first assembly (P1 > A1) and check the entire subtree to make sure A1 never appears in the subtree. Repeat this recursively until the entire tree is checked in this manner. Imagine a directory of folders in a file system that supports links to other folders. Begin navigating the file system by opening folders then subfolders until you have no subfolders remaining. Now imagine one folder contains a link to a folder that is higher in the directory tree. You would never be able to reach the end (the folder that contains no subfolders). -- 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.