Chris Curvey schrieb:
> I can't believe this is not a FAQ, but my Google skills are failing me
> at finding an answer.
> 
> 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?  I have a feeling that it has
> something to do with Alias, but I can't quite get the incantation.

You should simple be able to define a MultipleJoin to itself. Like this:

class Category(SQLObject):
     parent = ForeignKey("Category")
     children = MultipleJoin("Category")

I didn't test that, it might be that you need to give the 
joinColumn-attribute with "parent_id" or something.

Alternatively, you should be able to implement a method like this:

def children(self):
     return list(Category.select(Category.q.parentID == self.id))

No alias nowhere...

Diez

--~--~---------~--~----~------------~-------~--~----~
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