Rename lock_version field?


#1

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


#2

Phillip H. 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-


#3

On 1/4/06, Phillip H. removed_email_address@domain.invalid 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. :slight_smile:

–Wilson.