diff options
author | Jon Leighton <j@jonathanleighton.com> | 2012-03-04 10:03:34 -0800 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2012-03-04 10:03:34 -0800 |
commit | 2fdb5219fb70a6368602c9d6073be8fa70b720fa (patch) | |
tree | 2d177c38a9051cccf1125bd15e943bb4709b0d2f /activerecord/lib/active_record | |
parent | b83965785db1eec019edf1fc272b1aa393e6dc57 (diff) | |
parent | 200d994870e0b2e59c31ab9d268def19abc563cf (diff) | |
download | rails-2fdb5219fb70a6368602c9d6073be8fa70b720fa.tar.gz rails-2fdb5219fb70a6368602c9d6073be8fa70b720fa.tar.bz2 rails-2fdb5219fb70a6368602c9d6073be8fa70b720fa.zip |
Merge pull request #5267 from kennyj/fix_4674
Fix GH #4674. Reset column information and sequence name when setting table_name.
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/model_schema.rb | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/model_schema.rb b/activerecord/lib/active_record/model_schema.rb index 60bac2f802..73c9e22aa3 100644 --- a/activerecord/lib/active_record/model_schema.rb +++ b/activerecord/lib/active_record/model_schema.rb @@ -114,10 +114,17 @@ module ActiveRecord # 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 unless defined?(@explicitly_sequence_name) && @explicitly_sequence_name + @relation = Relation.new(self, arel_table) end # Returns a quoted version of the table name, used to construct SQL statements. @@ -163,7 +170,8 @@ module ActiveRecord end def reset_sequence_name #:nodoc: - self.sequence_name = connection.default_sequence_name(table_name, primary_key) + @sequence_name = connection.default_sequence_name(table_name, primary_key) + @explicitly_sequence_name = false end # Sets the name of the sequence to use when generating ids to the given @@ -182,6 +190,7 @@ module ActiveRecord # end def sequence_name=(value) @sequence_name = value.to_s + @explicitly_sequence_name = true end # Indicates whether the table associated with this class exists |