On Dec 26, 2011, at 9:56 AM, k.elkouhen wrote:

> In the example included in the 0.7 documentation, I can't figure out how the 
> code backref="left_nodes" works ?  
> 
> Notably, because I can't find a reference to left_nodes...

left_nodes and right_nodes are essentially equivalent collections:

n1, n2, n3, n4 = Node(label='n1'), Node(label='n2'), Node(label='n3'), 
Node(label='n4')

n1.left_nodes = [n2, n3]
n1.right_nodes = [n4]

assert n2.right_nodes == [n1]
assert n3.right_nodes == [n1]
assert n4.left_nodes == [n1]




> 
> from sqlalchemy import Integer, ForeignKey, String, Column, Table
> from sqlalchemy.ext.declarative import declarative_base
> from 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)
>     right_nodes = 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="left_nodes"
>     )
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To view this discussion on the web visit 
> https://groups.google.com/d/msg/sqlalchemy/-/Miy02_r3Pe4J.
> To post to this group, send email to sqlalchemy@googlegroups.com.
> To unsubscribe from this group, send email to 
> sqlalchemy+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/sqlalchemy?hl=en.

-- 
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 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to