From c353794dff580c8aa63b357b2857c1fadff3104b Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Wed, 30 Apr 2008 15:04:08 -0500 Subject: Fixed that pessimistic locking you reference the quoted table name (Josh Susser) [#67 state:resolved] --- activerecord/CHANGELOG | 2 ++ activerecord/lib/active_record/locking/optimistic.rb | 2 +- activerecord/test/cases/locking_test.rb | 9 ++++++++- activerecord/test/schema/schema.rb | 1 + 4 files changed, 12 insertions(+), 2 deletions(-) (limited to 'activerecord') diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG index e96c5096e5..154b282130 100644 --- a/activerecord/CHANGELOG +++ b/activerecord/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Fixed that pessimistic locking you reference the quoted table name (Josh Susser) [#67] + * Fixed that change_column should be able to use :null => true on a field that formerly had false [Nate Wiger] [#26] * Added that the MySQL adapter should map integer to either smallint, int, or bigint depending on the :limit just like PostgreSQL [DHH] diff --git a/activerecord/lib/active_record/locking/optimistic.rb b/activerecord/lib/active_record/locking/optimistic.rb index f2c2c5f070..65f88cfdc7 100644 --- a/activerecord/lib/active_record/locking/optimistic.rb +++ b/activerecord/lib/active_record/locking/optimistic.rb @@ -78,7 +78,7 @@ module ActiveRecord begin affected_rows = connection.update(<<-end_sql, "#{self.class.name} Update with optimistic locking") - UPDATE #{self.class.table_name} + UPDATE #{self.class.quoted_table_name} SET #{quoted_comma_pair_list(connection, attributes_with_quotes(false, false, attribute_names))} WHERE #{self.class.primary_key} = #{quote_value(id)} AND #{self.class.quoted_locking_column} = #{quote_value(previous_value)} diff --git a/activerecord/test/cases/locking_test.rb b/activerecord/test/cases/locking_test.rb index e80f902d0d..7db6c570b5 100644 --- a/activerecord/test/cases/locking_test.rb +++ b/activerecord/test/cases/locking_test.rb @@ -2,6 +2,7 @@ require "cases/helper" require 'models/person' require 'models/reader' require 'models/legacy_thing' +require 'models/reference' class LockWithoutDefault < ActiveRecord::Base; end @@ -15,7 +16,7 @@ class ReadonlyFirstNamePerson < Person end class OptimisticLockingTest < ActiveRecord::TestCase - fixtures :people, :legacy_things + fixtures :people, :legacy_things, :references # need to disable transactional fixtures, because otherwise the sqlite3 # adapter (at least) chokes when we try and change the schema in the middle @@ -138,6 +139,12 @@ class OptimisticLockingTest < ActiveRecord::TestCase end end end + + def test_quote_table_name + ref = references(:michael_magician) + ref.favourite = !ref.favourite + assert ref.save + end private diff --git a/activerecord/test/schema/schema.rb b/activerecord/test/schema/schema.rb index a9b2073b37..e22b78749c 100644 --- a/activerecord/test/schema/schema.rb +++ b/activerecord/test/schema/schema.rb @@ -206,6 +206,7 @@ ActiveRecord::Schema.define do t.integer :person_id t.integer :job_id t.boolean :favourite + t.integer :lock_version, :default => 0 end create_table :minimalistics, :force => true do |t| -- cgit v1.2.3