在documentation中指出
get() is special in that it provides direct access to the identity map of the owning Session.
这在许多方面类似于query.filter_by(id == id)
或query.filter(ModelClass.id == id)
(我假设ModelClass.id是它的主键)
在我看来,我总是希望使用query.get
,因为它更快(因为不必执行SELECT
)。我为什么要用filter_by(id=id)
.get
确实执行SELECT
当需要时,没有办法。但是,是的,.get
足够聪明,可以在可能的情况下绕过DB查询如果您只按
id
过滤,那么就没有理由使用filter
——这只是更一般的事情相关问题 更多 >
编程相关推荐