What's the difference between Model.query and session.query(Model) in SQLAlchemy?

前端 未结 3 1264
醉话见心
醉话见心 2020-12-12 20:40

I\'m a beginner in SQLAlchemy and found query can be done in 2 method:

Approach 1:

DBSession = scoped_session(sessionmaker())
class _Base(object):
           


        
3条回答
  •  粉色の甜心
    2020-12-12 21:07

    An answer (here) to a different SQLAlchemy question might help. That answer starts with:

    You can use Model.query, because the Model (or usually its base class, especially in cases where declarative extension is used) is assigned Sesssion.query_property. In this case the Model.query is equivalent to Session.query(Model).

提交回复
热议问题