Chris Curvey ha scritto:
> I can't believe this is not a FAQ,

Yes, it is..  googling "sql tree" gives relevant results on both web and 
newsgroups.

> If I have a hierarchy of categories, and my model looks like this:
>
> class Category(SQLObject):
>     name = UnicodeCol(length=100)
>     parent = ForeignKey("Category")
>
> How do I create a method on Category so that I can retrieve all the
> children for a Category instance?

You're working with trees of unbounded depth, by chance?

Keep in mind that an adjacency list like yours is not scalable. How many 
rows are there, or will ever be?
You are free to go with the simple implementation, until you have 
performance issues.

If, and when your data set grows and queries become slow, do not blame 
the DBMS, because it's time to use a more appropriate data structure.

You could for instance look for "SQL For Smarties" and "trees and 
hierarchies in SQL" by Joe Celko
For a summary of the treated concept, see 
http://www.dbazine.com/oracle/or-articles/tropashko4



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" 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/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to