youre looking for a self-referential mapper.  there are three  
examples of this in the examples/ directory (the "adjacencytree/"  
directory has two, and the "backref" directory has one).  also the  
docs have a quick example of a self-referential mapper in the  
advanced mapper section.  check out all of this stuff, and if you  
still have questions check back here.

On Sep 18, 2006, at 1:15 AM, Mongoose wrote:

> In a treelike hierarchical data design, each node will have a  
> parent ID, referring to another node, except for the root node(s)  
> which won't have a parent.  The trouble I'm having is that a parent  
> ID refers to the primary ID of another row in the same table.  I  
> don't know how to properly describe that relation in sqlalchemy.  
> Could anyone offer some advice?
>
> Another problem is I'm trying to refer to all the posts with the  
> same parent as the kits of that parent post.  I'd like it so the  
> kits were lazy loaded and accessible via parentobject.kits as a  
> list. Is that how it's supposed to turn out?
>
> This is what isn't working, but best I can figure is how it should  
> be done:
> mapper.add_property('parent',relation 
> (nodeclass,backref='kits',primaryjoin=nodeclass.c.id==nodeclass.c.pare 
> nt))
>
> You'll note my confusion in how is it supposed to tell which  
> nodeclass key is the foreign key, the id or the parent? I suppose  
> it could ask the database (which knows that the parent is the  
> foreign key) but still, grokking this eludes me.  I end up with  
> errors like the following:
>   File "/usr/lib/python2.4/site-packages/sqlalchemy/orm/ 
> properties.py", line 302, in _get_direction
>     if list(self.foreignkey)[0].primary_key:
> IndexError: list index out of range
>
> The above error only happens when I start trying to define the  
> 'kits' relation between nodes and ...nodes.  But without defining  
> the relation I am entirely unable to do certain essential tasks  
> like for instance:
> for childNode in parentNode.kits:
>       childNode.DisplayStuff()
>
> ---------------------------------------------------------------------- 
> ---
> Using Tomcat but need to do more? Need to support web services,  
> security?
> Get stuff done quickly with pre-integrated technology to make your  
> job easier
> Download IBM WebSphere Application Server v.1.0.1 based on Apache  
> Geronimo
> http://sel.as-us.falkag.net/sel? 
> cmd=lnk&kid=120709&bid=263057&dat=121642
> _______________________________________________
> Sqlalchemy-users mailing list
> Sqlalchemy-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to