mlzboy
mlzboy

Reputation: 14701

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

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 = "dddd"

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

Upvotes: 0

Views: 47

Answers (2)

rwilliams
rwilliams

Reputation: 21497

try

u.reload

It'll reload the entity from the database.

Upvotes: 2

nonopolarity
nonopolarity

Reputation: 151126

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.

Upvotes: 1

Related Questions