Skip to content

Commit

Permalink
Don't clear sequence name when we explicitly assign it.
Browse files Browse the repository at this point in the history
  • Loading branch information
kennyj committed Mar 4, 2012
1 parent 640f6c2 commit 200d994
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
6 changes: 4 additions & 2 deletions activerecord/lib/active_record/model_schema.rb
Expand Up @@ -123,7 +123,7 @@ def table_name=(value)
@table_name = value
@quoted_table_name = nil
@arel_table = nil
@sequence_name = nil
@sequence_name = nil unless defined?(@explicitly_sequence_name) && @explicitly_sequence_name
@relation = Relation.new(self, arel_table)
end

Expand Down Expand Up @@ -170,7 +170,8 @@ def sequence_name
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
Expand All @@ -189,6 +190,7 @@ def reset_sequence_name #:nodoc:
# end
def sequence_name=(value)
@sequence_name = value.to_s
@explicitly_sequence_name = true
end

# Indicates whether the table associated with this class exists
Expand Down
11 changes: 11 additions & 0 deletions activerecord/test/cases/base_test.rb
Expand Up @@ -1492,6 +1492,17 @@ def test_clear_cash_when_setting_table_name
assert_not_equal before_seq, after_seq unless before_seq.blank? && after_seq.blank?
end

def test_dont_clear_sequence_name_when_setting_explicitly
Joke.sequence_name = "black_jokes_seq"
Joke.table_name = "cold_jokes"
before_seq = Joke.sequence_name

Joke.table_name = "funny_jokes"
after_seq = Joke.sequence_name

assert_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
Expand Down

0 comments on commit 200d994

Please sign in to comment.