That worked, except that I had to skip the secondary kwarg on the
backref. If I include it, I get:
<type 'exceptions.TypeError'>: __init__() got multiple values for
keyword argument 'secondary'
So it seems that it is assuming that I will use the same secondary
table for the backref but not that I am using the same (or, rather,
flipped) join conditions? That doesn't make too much sense to me
(although practically speaking, it is certainly not that big a deal to
have to specify the join conditions again in the backref). I will put
a bug in trac later today to track this issue for .5

Also, this is my first time using a relation with uselist set to false
and I was surprised that if multiple objects meet the condition it
just hands me the first one. Since getting the value of a relation
that has uselist=False is (in my mind) the moral equivalent of using
one() on a query, I had been hoping it would raise if multiple rows
were returned.


On Wed, May 7, 2008 at 8:22 PM, Michael Bayer <[EMAIL PROTECTED]> wrote:
>
>
>
>  On May 7, 2008, at 7:23 PM, Bobby Impollonia wrote:
>
>  >
>  > 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.
>
>
>  when you specify primaryjoin/secondaryjoin to relation(), those
>  arguments are not copied into the backref automatically, since you've
>  gone explicit (perhaps this should be adjusted in 0.5).  So you need
>  to use backref=backref('the_backref', primaryjoin=<join>,
>  secondaryjoin=<otherjoin>, secondary=<table>, foreign_keys=<keys>) in
>  this case.
>
>
>
>
>  >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected]
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