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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to