On Aug 18, 2008, at 8:41 PM, Tom wrote:
> > I am trying to build a self-referential mapper like the basic_tree > example, but would like to be able to access the root of any given > TreeNode, much like the now depreciated and tricky byroot_tree.py. > Before you tell me just to use the byroot_tree, zzzeek has already > told me to work with eager loading and the byroot_tree has some issues > loading currently. > > http://svn.sqlalchemy.org/sqlalchemy/tags/rel_0_5beta3/examples/adjacencytree/basic_tree.py > http://svn.sqlalchemy.org/sqlalchemy/tags/rel_0_5beta3/examples/adjacencytree/byroot_tree.py > > So here is my issue: whenever I try to modify basic_tree to keep track > of root_id's and map the root property I run into the following > problem: > > "ArgumentError: Could not determine join condition between parent/ > child tables on relation Node.children. > Specify a 'primaryjoin' expression. If this is a many-to-many > relation, 'secondaryjoin' is needed as well." > > Note, this is even when I use a primaryjoin similar to the byroot > example: > > root=relation(Node, primaryjoin=trees.c.root_id==trees.c.id, > remote_side=trees.c.id, lazy=None) > > Can anyone help me convert the eager loading example to allow root > access? This is particularly important because every time I load a > TreeNode, I want to be able to access the root, and I also want to be > able to retrieve all the TreeNodes for a given root_id. its just like the byroot_tree.... mapper(TreeNode, trees, properties={ 'children': relation(TreeNode, cascade="all", backref=backref("parent", remote_side=[trees.c.id]), collection_class=attribute_mapped_collection('name'), lazy=False, join_depth=3, primaryjoin=trees.c.parent_id==trees.c.id ), 'root':relation(TreeNode, primaryjoin=trees.c.root_id==trees.c.id, remote_side=trees.c.id) }) You'd have to use part of byroot_tree's MapperExtension to have root_id populated upon flush(). And as I've said, the "append_result" part would work more nicely if you only used it on a per-query basis using query.options(extension(MyExt()), so that it doesnt get in the way for queries which don't want specialized append_result() behavior. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---