I apologize if this is well trodden ground, but having googled, and 
stack-overflowed, read the docs, and searched this list, where lots of 
people have asked the same (or similar) questions, I couldn't find a 
concrete answer...

I'm trying to set up a Model such that an entry can be connected to one or 
more other entries, and that the reverse relationship can be found from the 
same attribute.

Effectively I'm trying to do this:

```

from sqlalchemy import Integer, ForeignKey, String, Column, Tablefrom 
sqlalchemy.ext.declarative import declarative_basefrom sqlalchemy.orm import 
relationship
Base = declarative_base()
node_to_node = Table("node_to_node", Base.metadata,
    Column("left_node_id", Integer, ForeignKey("node.id"), primary_key=True),
    Column("right_node_id", Integer, ForeignKey("node.id"), primary_key=True))
class Node(Base):
    __tablename__ = 'node'
    id = Column(Integer, primary_key=True)
    label = Column(String)
    connected = relationship("Node",
                        secondary=node_to_node,
                        primaryjoin=id==node_to_node.c.left_node_id,
                        secondaryjoin=id==node_to_node.c.right_node_id,
                        backref="connected"
    )

```

However, that naturally fails (`Error creating backref 'translations' on 
relationship 'Sentence.translations': property of that name exists`) as 
there's no magic to figure out that `translations` should be 
bi-directional. 

Is there another way to achieve this?

Thanks!

Matt.

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to