Browse files

Don't reset inheritance_column when setting explicitly.

This is backported from master (cdfcbc4).
  • Loading branch information...
1 parent dbd26e9 commit 55e295470303a6abcf152f24a1a8c7864dab5ef6 @fredwu fredwu committed Mar 6, 2013
Showing with 13 additions and 1 deletion.
  1. +3 −1 activerecord/lib/active_record/model_schema.rb
  2. +10 −0 activerecord/test/cases/base_test.rb
View
4 activerecord/lib/active_record/model_schema.rb
@@ -173,6 +173,7 @@ def original_inheritance_column #:nodoc:
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 @@ def reset_column_information
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
View
10 activerecord/test/cases/base_test.rb
@@ -1540,6 +1540,16 @@ def test_switching_between_table_name
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

0 comments on commit 55e2954

Please sign in to comment.