开发者

How to abandon/rollback the modifications done into a model entity?

开发者 https://www.devze.com 2023-01-27 17:40 出处:网络
I changed some value of an entity from the db, but now I want to discard all the changes. How can I do this?

I changed some value of an entity from the db, but now I want to discard all the changes. How can I do this?

I tried following:

    u = User.find(1)
    u.nick =开发者_Python百科 "dddd"

    u.abandon?  #i didn't want rollback the chage of the u 


try

u.reload

It'll reload the entity from the database.


if you don't save it (by using u.save), then it is not made into the persistent storage. You can just do u = User.find(1) again to reload the value from the db.

0

精彩评论

暂无评论...
验证码 换一张
取 消