for an association pattern, you need to construct an explicit class with its own mapper to handle the association..in this case it would be something like mapper(NodeAssociation, node_association_table). The "primaryjoin" option is only meant to deal with the direct parent and child tables, in your case below its just "node" since it has no knowledge of "node_association_table".
if you want to look into reducing the attribute indirection introduced by NodeAssociation (i.e. somenode.association.child), take a look at the AssociationProxy extension. On Sep 1, 2007, at 5:41 PM, Aaron R wrote: > > Hello, I am trying to create a self reference so that a Node has > children and parents but the information is stored in an association > parent so that a Node can have more than one parent. > > http://www.sqlalchemy.org/docs/04/ > mappers.html#advdatamapping_relation_selfreferential > > Tables like this: > > node_table = Table("node", model.metadata, > Column("id", Integer, primary_key=True), > Column("title", String(255), nullable=False), > Column("customer_id", Integer, ForeignKey('customer.id')), > Column("content", String, default=''), > Column("created", DateTime), > Column("createdby_id", Integer, default=24), > Column("username", String, default='') > ) > node_association_table = Table('nodelink', model.metadata, > Column("id", Integer, primary_key=True), > Column('child_id', Integer, ForeignKey('node.id')), > Column('parent_id', Integer, ForeignKey('node.id')), > ) > > mapper(Node, node_table, properties={ > 'children':relation(Node, > primaryjoin=(node_association_table.c.parent_id==Node.c.id)), > 'parents':relation(Node, > primaryjoin=(node_association_table.c.child_id==Node.c.id)), > }) > > I have tried several (many) variations on how to relate, and it seems > that no matter what it doesn't want the same type (Node) to be listed > twice? > > Any suggestions would be much appreciated. I also looked at the tree > examples, but they all only supported one parent. > http://www.sqlalchemy.org/trac/browser/sqlalchemy/trunk/examples/ > adjacencytree > > Thanks > > Aaron > > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---