Forum: Ruby on Rails Rename lock_version field?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
B73078bb51c1cb08c61e4cf6431f11bd?d=identicon&s=25 Phillip Hershkowitz (phersh)
on 2006-01-05 00:37
Hi,

Is there a way to tell Rails that the magic field name for optimistic
database locking is not lock_version? I have a legacy database where the
optimistic locking field is named "version".

Thanks,
Phil
8559d0a815c0c7a11f8a19538bf336c6?d=identicon&s=25 John Cabrer (jcabrer)
on 2006-01-05 00:53
Phillip Hershkowitz wrote:
> Hi,
>
> Is there a way to tell Rails that the magic field name for optimistic
> database locking is not lock_version? I have a legacy database where the
> optimistic locking field is named "version".
>
> Thanks,
> Phil

Hi Phil,

To do what you suggest, you would begin by modifying

C:\ruby\lib\ruby\gems\1.8\gems\activerecord-1.13.2\lib\active_record\locking.rb

replace every occurance of "lock_version" with "version"

Beyond this, I am sure there must be other places where you must do the
same thing, but I've not taken the time to look into it further.

Ideally, things like this should be defineable somehow, like

#define lock_version_field_name = "version"

but this is not something readyli available in rails.  At least not that
I know of (and I don't know all that much).

Good luck.

-John-
25e11a00a89683f7e01e425a1a6e305c?d=identicon&s=25 Wilson Bilkovich (Guest)
on 2006-01-05 21:03
(Received via mailing list)
On 1/4/06, Phillip Hershkowitz <philhersh@hotmail.com> wrote:
> Hi,
>
> Is there a way to tell Rails that the magic field name for optimistic
> database locking is not lock_version? I have a legacy database where the
> optimistic locking field is named "version".
>
> Thanks,
> Phil
>

I just made a patch against the stable version of Rails that lets you
set the name of the locking column on your model classes.

Example:

class LegacyThing < ActiveRecord::Base
  set_locking_column :version
end

If you don't specify a column name, it defaults to lock_version.  So
far I've only tested it against Oracle, but it basically doesn't
change the SQL code, so you should be fine with other DBMSes.

The patch is against revision 3381, the latest stable version, but it
should apply against anything, since the locking.rb file hasn't been
changed in 6 months.

Hopefully this will help you out. :)

--Wilson.
This topic is locked and can not be replied to.