【发布时间】:2017-11-29 19:57:34
【问题描述】:
我有以下场景:
class A(Base):
a_string = Column(String)
class B(Base):
id = Column(Integer, primary_key=True)
class C(Base):
b_id = Column(Integer, ForeignKey(B.id))
value = Column(String)
我需要做以下查询:
SELECT c2.*
FROM a
JOIN c c1 on c1.value = a.a_string
JOIN c c2 on c2.b_id = c1.b_id
问题是我需要在模型 A 内部的关系中进行上述查询。类似于:
class A(Base):
a_string = Column(String)
c_list = relationship('C', secondary=...)
【问题讨论】:
标签: python sqlalchemy