aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2013-03-26 15:22:05 -0700
committerRafael Mendonça França <rafaelmfranca@gmail.com>2013-03-26 15:22:05 -0700
commitdf37c91745a3fb241fafa23c03387e33eb82c74f (patch)
tree92b4cb9321a20d1ee03f32c982ac8f332b5469ee
parentdbd26e92a7b943a57c2826a749ae25e3ce9e143c (diff)
parent8bd56f0f7ad2b48a50f12c49d436a469fdbb7135 (diff)
downloadrails-df37c91745a3fb241fafa23c03387e33eb82c74f.tar.gz
rails-df37c91745a3fb241fafa23c03387e33eb82c74f.tar.bz2
rails-df37c91745a3fb241fafa23c03387e33eb82c74f.zip
Merge pull request #9576 from fredwu/backport_fix_explicitly_inheraitance_column_to_3_2_stable
[Backport to 3-2-stable] Don't reset inheritance_column when setting explicitly.
-rw-r--r--activerecord/CHANGELOG.md5
-rw-r--r--activerecord/lib/active_record/model_schema.rb4
-rw-r--r--activerecord/test/cases/base_test.rb10
3 files changed, 18 insertions, 1 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md
index c0e0bb1dbc..9e6d44c8f0 100644
--- a/activerecord/CHANGELOG.md
+++ b/activerecord/CHANGELOG.md
@@ -1,5 +1,10 @@
## unreleased ##
+* Do not reset `inheritance_column` when it's set explicitly.
+ Backport of #5327.
+
+ *kennyj + Fred Wu*
+
* Fix a problem wrong exception is occured
when raising no translatable exception in PostgreSQL.
diff --git a/activerecord/lib/active_record/model_schema.rb b/activerecord/lib/active_record/model_schema.rb
index 1517e5ec17..e10e6b4aa8 100644
--- a/activerecord/lib/active_record/model_schema.rb
+++ b/activerecord/lib/active_record/model_schema.rb
@@ -173,6 +173,7 @@ module ActiveRecord
def inheritance_column=(value)
@original_inheritance_column = inheritance_column
@inheritance_column = value.to_s
+ @explicit_inheritance_column = true
end
def set_inheritance_column(value = nil, &block) #:nodoc:
@@ -300,7 +301,8 @@ module ActiveRecord
connection.schema_cache.clear_table_cache!(table_name) if table_exists?
@column_names = @content_columns = @column_defaults = @columns = @columns_hash = nil
- @dynamic_methods_hash = @inheritance_column = nil
+ @dynamic_methods_hash = nil
+ @inheritance_column = nil unless defined?(@explicit_inheritance_column) && @explicit_inheritance_column
@arel_engine = @relation = nil
end
diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb
index 97d6c0cf88..67b5d174aa 100644
--- a/activerecord/test/cases/base_test.rb
+++ b/activerecord/test/cases/base_test.rb
@@ -1540,6 +1540,16 @@ class BasicsTest < ActiveRecord::TestCase
end
end
+ def test_dont_clear_inheritnce_column_when_setting_explicitly
+ Joke.inheritance_column = "my_type"
+ before_inherit = Joke.inheritance_column
+
+ Joke.reset_column_information
+ after_inherit = Joke.inheritance_column
+
+ assert_equal before_inherit, after_inherit unless before_inherit.blank? && after_inherit.blank?
+ end
+
def test_set_table_name_symbol_converted_to_string
Joke.table_name = :cold_jokes
assert_equal 'cold_jokes', Joke.table_name