secondary_table = Table('secondary', Base.metadata,
    Column('left_id', Integer, ForeignKey('parent.id'), nullable=False),
    Column('right_id', Integer, ForeignKey('parent.id'), nullable=False))

class Parent(Base):
    __tablename__ = 'parent'
    id = Column(Integer, primary_key=True)
    cls = Column(String(50))
    __mapper_args__ = dict(polymorphic_on = cls )

class Child1(Parent):
    __tablename__ = 'child1'
    id = Column(Integer, ForeignKey('parent.id'), primary_key=True)
    __mapper_args__ = dict(polymorphic_identity = 'child1',
inherit_condition=Parent.id==id)

class Child2(Parent):
    __tablename__ = 'child2'
    id = Column(Integer, ForeignKey('parent.id'), primary_key=True)
    __mapper_args__ = dict(polymorphic_identity = 'child2')

Child1.left_child2 = relation(Child2, secondary = secondary_table,
        primaryjoin = Child1.c.id == secondary_table.c.right_id,
        secondaryjoin = Child2.c.id == secondary_table.c.left_id,
        uselist = False,
        foreign_keys = [secondary_table.c.left_id,
                        secondary_table.c.right_id],
        backref = 'the_backref')

The first time I try to create an object or do a query, I get:
<class 'sqlalchemy.exceptions.ArgumentError'>: Could not determine
relation direction for primaryjoin condition 'child2.id =
secondary.left_id', on relation Child2.the_backref (Child1). Specify
the foreign_keys argument to indicate which columns on the relation
are foreign.

However, if I remove the backref, the left_child2 property works fine,
so this only seems to be failing in one direction.

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to