# Can lock\_version be ignored?

**URL:** <https://www.ruby-forum.com/t/can-lock-version-be-ignored/141136>\
**Category:** Rails\
**Created:** [June 22, 2008, 1:13pm UTC](https://www.ruby-forum.com/t/can-lock-version-be-ignored/141136 "2008-06-22T13:13:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![S-gw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@S-gw](https://www.ruby-forum.com/u/S-gw)\
**Post date:** [June 22, 2008, 1:13pm UTC](https://www.ruby-forum.com/t/can-lock-version-be-ignored/141136/1 "2008-06-22T13:13:30Z")

</div>

I have a need to update a record but without changing the  
lock\_version – or to at least .save without triggering a stale error  
if the lock\_version has changed.

Is either possible? I’ve tried the API and some blogs, so far no  
hints…

– gw

---

<div class="post-metadata">

**Author:** ![S-gw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ed655f/32.png) [@S-gw](https://www.ruby-forum.com/u/S-gw)\
**Post date:** [June 22, 2008, 6:27pm UTC](https://www.ruby-forum.com/t/can-lock-version-be-ignored/141136/2 "2008-06-22T18:27:00Z")

</div>

On 22 Jun 2008, at 12:12, Greg W. wrote:

> I have a need to update a record but without changing the  
> lock\_version – or to at least .save without triggering a stale error  
> if the lock\_version has changed.
> 
> Is either possible? I’ve tried the API and some blogs, so far no  
> hints…

def without\_locking  
old\_value, ActiveRecord::Base.lock\_optimistically =  
ActiveRecord::Base.lock\_optimistically, false  
yield  
ensure  
ActiveRecord::Base.lock\_optimistically = old\_value  
end

You could whack that into activerecord if you used it often enough.  
That said, if I wanted to ignore optimisic locking then I probably  
wouldn’t be using it in the first place.

Fred
