On Jul 22, 2008, at 6:50 AM, Erez wrote:
> > Hi, > I apologize in advance if this is a newbie question, but this is > pretty wierd and I couldn't find an answer in the docs. > > I have these two "tables": > > class Node(Base): > __tablename__ = 'nodes' > > id = Column(Integer, primary_key=True) > name = Column(String) > > > class Link(Base): > __tablename__ = 'links' > > node_id = Column(Integer, ForeignKey('nodes.id')) > > id = Column(Integer, primary_key=True) > type = Column(String) > fro = relation(Node, order_by=Node.id, backref="links_out") > to = relation(Node, order_by=Node.id, backref="links_in") > > > Just to clarify, I want each link to appear in the "links_out" of its > from-node, and in the links_in of it's to-node. > > This works just fine when I create the classes, but once I commit the > changes into a session, everything gets messed up (maybe the links_in > and links_out aren't seperated as I would expect). > > A quick example: >>>> sqlalchemy.__version__ > '0.5.0beta2' >>>> cat = Node() >>>> cat.name = "cat" >>>> animal = grm.Node() >>>> animal.name = "animal" >>>> link = Link() >>>> link.type = "is a" >>>> link.fro = cat >>>> link.to = animal >>>> link > #cat >is a> #animal >>>> session.add(cat) >>>> session.add(animal) >>>> session.add(link) >>>> session.commit() >>>> link > #animal >is a> #animal you have only one foreign key to the "nodes" table, but two relations. How can a single row in "links" maintain two separate references to both "fro" and "to" ? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---