However, it doesn’t do any kind of query caching. This means, if you say session.query(Foo).filter_by(name='bar'), even if Foo(name='bar') is right there, in the identity map, the session has no idea about that. It has to issue SQL to the database, get the rows back, and then when it sees the primary key in the row, then it can look in the local identity map and see that the object is already there.
“脏属性会影响
session.query
”的简短答案是no,如"Is the Session a cache?"中所述:实际上,这并不是那么简单,因为在其默认配置中,SQLAlchemy会定期将保存在
Session
中的更改刷新到数据库中。这被称为autoflush,它确保向数据库发出的查询能够观察到它在Session
中的状态。你知道吗在"What does the Session do ?"中还指出
因此,如果您禁用了自动刷新,或者处于无法进行刷新的上下文中,则必须手动处理脏对象。你知道吗
相关问题 更多 >
编程相关推荐