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.
On Fri, Aug 26, 2011 at 7:31 PM, News A. [email protected]
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.
–
News A. 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 §
Component Part ©
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).