Just as the title said. All I want to do is get the return id (auto generate primary key) from the session after session.add. If I commit the transacti开发者_高级运维on manually without using pyramid_tm all is fine, but when I start using pyramid_tm, it seems to ignore expire_on_commit. Any suggestions?
It doesn't ignore expire_on_commit, it's just that the transaction isn't committed until after your code has run, so you need to flush and refresh. This is how I do it:
thing = Thing()
Session.add(thing)
Session.flush()
Session.refresh(thing)
print thing.id
精彩评论