aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2011-02-08 16:01:16 -0800
committerAaron Patterson <aaron.patterson@gmail.com>2011-02-08 16:01:16 -0800
commit1c6f4562d788cd5b63889b9597bc1765a1bd75e0 (patch)
tree675332c9f09d1f86b38f068371b64db6893d00fe /activerecord
parent11061f410eca48c3a1922ade001bc54927e6b8c7 (diff)
downloadrails-1c6f4562d788cd5b63889b9597bc1765a1bd75e0.tar.gz
rails-1c6f4562d788cd5b63889b9597bc1765a1bd75e0.tar.bz2
rails-1c6f4562d788cd5b63889b9597bc1765a1bd75e0.zip
primary keys should not be cleared on cache clear, fixing oracle tests
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/attribute_methods/primary_key.rb1
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb2
-rw-r--r--activerecord/lib/active_record/relation.rb9
-rw-r--r--activerecord/test/cases/base_test.rb5
-rw-r--r--activerecord/test/cases/connection_pool_test.rb4
5 files changed, 15 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/attribute_methods/primary_key.rb b/activerecord/lib/active_record/attribute_methods/primary_key.rb
index 978cd7fbe3..fcdd31ddea 100644
--- a/activerecord/lib/active_record/attribute_methods/primary_key.rb
+++ b/activerecord/lib/active_record/attribute_methods/primary_key.rb
@@ -56,6 +56,7 @@ module ActiveRecord
@primary_key ||= ''
self.original_primary_key = @primary_key
value &&= value.to_s
+ connection_pool.primary_keys[table_name] = value
self.primary_key = block_given? ? instance_eval(&block) : value
end
end
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
index b1754e61df..4297c26413 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb
@@ -128,12 +128,10 @@ module ActiveRecord
#
# * columns
# * columns_hash
- # * primary_keys
# * tables
def clear_cache!
@columns.clear
@columns_hash.clear
- @primary_keys.clear
@tables.clear
end
diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb
index 1441e9750e..852f4077f2 100644
--- a/activerecord/lib/active_record/relation.rb
+++ b/activerecord/lib/active_record/relation.rb
@@ -32,7 +32,14 @@ module ActiveRecord
def insert(values)
im = arel.compile_insert values
im.into @table
- primary_key_value = primary_key && Hash === values ? values[table[primary_key]] : nil
+
+ primary_key_value = nil
+
+ if primary_key && Hash === values
+ primary_key_value = values[values.keys.find { |k|
+ k.name == primary_key
+ }]
+ end
@klass.connection.insert(
im.to_sql,
diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb
index 1730d9fb56..20a16cc8ac 100644
--- a/activerecord/test/cases/base_test.rb
+++ b/activerecord/test/cases/base_test.rb
@@ -50,6 +50,11 @@ class Boolean < ActiveRecord::Base; end
class BasicsTest < ActiveRecord::TestCase
fixtures :topics, :companies, :developers, :projects, :computers, :accounts, :minimalistics, 'warehouse-things', :authors, :categorizations, :categories, :posts
+ def test_columns_should_obey_set_primary_key
+ pk = Subscriber.columns.find { |x| x.name == 'nick' }
+ assert pk.primary, 'nick should be primary key'
+ end
+
def test_primary_key_with_no_id
assert_nil Edge.primary_key
end
diff --git a/activerecord/test/cases/connection_pool_test.rb b/activerecord/test/cases/connection_pool_test.rb
index 55ac1bc406..0c545b7e9d 100644
--- a/activerecord/test/cases/connection_pool_test.rb
+++ b/activerecord/test/cases/connection_pool_test.rb
@@ -18,16 +18,14 @@ module ActiveRecord
assert_equal columns_hash, @pool.columns_hash['posts']
end
- def test_clearing_cache
+ def test_clearing_column_cache
@pool.columns['posts']
@pool.columns_hash['posts']
- @pool.primary_keys['posts']
@pool.clear_cache!
assert_equal 0, @pool.columns.size
assert_equal 0, @pool.columns_hash.size
- assert_equal 0, @pool.primary_keys.size
end
def test_primary_key