Thanks, Erik, for your idea.
And if I create a method to dynamically set the path?(to eliminate the problem of reallocating categories?)
I will try right now.
Thank you again.
At 15:35 -0200 10/31/00, Nilton Lessa wrote:
>I am trying to build a database with 2 Tables; >1- Table 1 {name, URL, objectPRT to Table 2} > >2- Table 2{category, desciption, objectPTR to self} , trying to implement >subcategory, subsubcategory,and so on. > >Suppose that I have on Table 2: >Category A >Category B points to A (subcategory of A) >Category C point to B (subcategory of B) > >And on Table 1: >Record1 points to CAtegory C. > >I would like to be able to find this record even if I search by Category B >(its father) or Category A(its grandfather), and so on. > >Is it possible to construct a SQL command to do this?
Hi, Nilton --
I do something much like this in one of my applications. I had to keep track of not only the fact that B and C were subcategories of A, but also the ordering of the categories; e.g., that B as a category came between A and B.
I did this by creating a VarChar field called "path" which contains the hierarchical path of the category record. So the record for Category C in your example would have a path of:
A B C
If you index this field by word, then you can search for "B" and find the records for categories B and C in your example.
In my case, I use the first few letters of a category's full name for its path element, so new subcategories will, if sorted by path, sort properly in with existing ones.
When I create a new category, I simply assign its parent category, and the whole path is then inferred from there.
This approach works splendidly in all ways, and I have been very pleased with it. The only drawback that I can think of is that it would be difficult to shift your hierarchy around if you decided that some subcategories really belonged under different parent categories.
Hope this helps,
Erik ______________________________________________________________________ Erik D. Mueller-Harder, Editor Praxis News Digest http://pnd.praxisworks.com/
------------------------------------------------------------- The Valentina mailing list is brought to you by MacServe.net For info on lists services, see http://www.macserve.net/lists.html
------------------------------------------------------------- The Valentina mailing list is brought to you by MacServe.net For info on lists services, see http://www.macserve.net/lists.html ©2000 Nilton Lessa |