If I have an exception while trying to save an object, how can I tell Rails that it's not saved yet?
The object has a lock_version (used for optimistic locking). This is what I do:
ins = MyClass.new( arguments ) begin transaction do ins.save! bunch_of_other_stuff() end rescue ins.save! # problem here! end
The object's save() sets the internal object state in a saved mode. It actually isn't saved because the transaction failed. I can't reload it, because it's not in the database yet, and all subsequent saves are failing because the lock_version is wrong.
What I currently do, as a work-around is create a new instance of the object: new_ins = MyClass.new ( ins.attributes )
Is there any way I can tell Rails that this object was never saved before?
Thanks, Amir