Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix GH #4674. Reset column information and sequence name when setting…

… table_name.
  • Loading branch information...
commit 640f6c201d59cd7fc16943154372d4ef754f33f4 1 parent 223549f
@kennyj kennyj authored
View
15 activerecord/lib/active_record/model_schema.rb
@@ -114,10 +114,17 @@ def table_name
# You can also just define your own <tt>self.table_name</tt> method; see
# the documentation for ActiveRecord::Base#table_name.
def table_name=(value)
- @table_name = value && value.to_s
- @quoted_table_name = nil
- @arel_table = nil
- @relation = Relation.new(self, arel_table)
+ value = value && value.to_s
+ if defined?(@table_name)
+ return if value == @table_name
+
+ reset_column_information
+ end
+ @table_name = value
+ @quoted_table_name = nil
+ @arel_table = nil
+ @sequence_name = nil
+ @relation = Relation.new(self, arel_table)
end
# Returns a quoted version of the table name, used to construct SQL statements.
View
13 activerecord/test/cases/base_test.rb
@@ -1479,6 +1479,19 @@ def test_switching_between_table_name
end
end
+ def test_clear_cash_when_setting_table_name
+ Joke.table_name = "cold_jokes"
+ before_columns = Joke.columns
+ before_seq = Joke.sequence_name
+
+ Joke.table_name = "funny_jokes"
+ after_columns = Joke.columns
+ after_seq = Joke.sequence_name
+
+ assert_not_equal before_columns, after_columns
+ assert_not_equal before_seq, after_seq unless before_seq.blank? && after_seq.blank?
+ end
+
def test_set_table_name_symbol_converted_to_string
Joke.table_name = :cold_jokes
assert_equal 'cold_jokes', Joke.table_name
Please sign in to comment.
Something went wrong with that request. Please try again.