如何急切地加载SQLAlchemy中的所有关系
我有以下型号:如何急切地加载SQLAlchemy中的所有关系,sqlalchemy,Sqlalchemy,我有以下型号: class Item(Base): a = relationship(<whatever>) b = relationship(<whatever>) c = relationship(<whatever>) d = relationship(<whatever>) other_stuff = Column(<whatever>) 但我觉得这是一个非常常见的用例,必须有一个更漂亮
class Item(Base):
a = relationship(<whatever>)
b = relationship(<whatever>)
c = relationship(<whatever>)
d = relationship(<whatever>)
other_stuff = Column(<whatever>)
但我觉得这是一个非常常见的用例,必须有一个更漂亮的方法来实现它。你可以简单地说
.options(joinedload('*'))
参考:为什么不在以下项上创建一个helper(静态)方法:
def query\u with_all(cls):return session.query(cls).options(…)…
?如果我必须单独为每个属性打开连接加载,我肯定会以这种方式实现它。但我希望这种方法已经在SQLalchemy中实现了。看起来不是,据我所知(并且从这里缺乏响应判断),我不知道这是为关系
实现的,方式类似于列上的。
query(Item).options(joinedload('a')).options(joinedload('b')).options(joinedload('c')).options(joinedload('d'))