我有三个结构,它们之间的每个可能的关系点都有数据(称它们为 a、b 和 c)。我像这样声明这些关系(与关联的表)......
class A(Base):
__tablename__ = 'a'
id = Column( types.Integer(), primary_key = True )
abs = orm.relation( 'AB' )
acs = orm.relation( 'AC' )
# similarly for b and c
class AB(Base):
__tablename__ = 'ab'
id = Column( types.Integer(), primary_key = True )
a_id = Column( types.Integer(), ForeignKey( 'a.id' ) )
b_id = Column( types.Integer(), ForeignKey( 'b.id' ) )
a = orm.relation( 'A' )
b = orm.relation( 'B' )
abcs = orm.relation( 'ABC' )
acs = association_proxy( 'abcs', 'ac' )
# similarly for ac
class ABC(Base):
__tablename__ = 'abc'
id = Column( types.Integer(), primary_key = True )
ab_id = Column( types.Integer(), ForeignKey( 'ab.id' ) )
ac_id = Column( types.Integer(), ForeignKey( 'ac.id' ) )
ab = orm.relation( 'AB' )
ac = orm.relation( 'AC' )
现在以下代码失败:
abs = db.session.query( AB ).join( A ).join( AC ).join( C ).join( B ).join( ABC, and_(
ABC.ab_id == AB.id,
ABC.ac_id == AC.id
) ).all()
以上产生以下错误:
ArgumentError: Can't determine join between 'Join object on Join object on Join object on Join object on Join object on ab(163066988) and a(162822028)(175636236) and ac(162854924)(2936229868) and c(161105164)( 2936272780)'和'abc';表之间存在多个外键约束关系。请明确指定此连接的“onclause”。