sqlalchemy嵌套对象关系急切加载

时间:2015-11-05 21:50:30

标签: python join orm sqlalchemy

如何从C加载所有相关类C.B.A

1)一个典型的查询(使用两个连接) VS 2)急切加载

class A(Base):
    __tablename__ = 'a'



class B(Base):
    __tablename__ = 'b'
    id = Column(Integer, primary_key=True)
    a_id = Column(Integer, ForeignKey('a.id'))

    a = relationship(A)


class C(Base):
    __tablename__ = 'c'
    id = Column(Integer, primary_key=True)
    b_id = Column(Integer, ForeignKey('b.id'))

    b = relationship(B)

0 个答案:

没有答案