aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2011-11-29 16:33:50 +0000
committerJon Leighton <j@jonathanleighton.com>2011-11-29 20:13:37 +0000
commit7af719e81c46d06f50cd9b3caff38b945c5f2d84 (patch)
tree48186ea74bb6186d18b245598f0188a40a3ef901 /activerecord/lib/active_record
parentfd7ca98bb6218de42b821d48db083ea8c0e97d67 (diff)
downloadrails-7af719e81c46d06f50cd9b3caff38b945c5f2d84.tar.gz
rails-7af719e81c46d06f50cd9b3caff38b945c5f2d84.tar.bz2
rails-7af719e81c46d06f50cd9b3caff38b945c5f2d84.zip
Deprecate set_sequence_name in favour of self.sequence_name=
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/base.rb39
1 files changed, 28 insertions, 11 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index 40fa010558..9f173a4bcc 100644
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -734,16 +734,16 @@ module ActiveRecord #:nodoc:
end
end
- # Lazy-set the sequence name to the connection's default. This method
- # is only ever called once since set_sequence_name overrides it.
- def sequence_name #:nodoc:
- reset_sequence_name
+ def sequence_name
+ if superclass == Base
+ @sequence_name ||= reset_sequence_name
+ else
+ (@sequence_name ||= nil) || superclass.sequence_name
+ end
end
def reset_sequence_name #:nodoc:
- default = connection.default_sequence_name(table_name, primary_key)
- set_sequence_name(default)
- default
+ self.sequence_name = connection.default_sequence_name(table_name, primary_key)
end
# Sets the name of the sequence to use when generating ids to the given
@@ -758,12 +758,29 @@ module ActiveRecord #:nodoc:
# will discover the sequence corresponding to your primary key for you.
#
# class Project < ActiveRecord::Base
- # set_sequence_name "projectseq" # default would have been "project_seq"
+ # self.sequence_name = "projectseq" # default would have been "project_seq"
# end
- def set_sequence_name(value = nil, &block)
- define_attr_method :sequence_name, value, &block
+ def sequence_name=(value)
+ @sequence_name = value.to_s
+ end
+
+ def set_sequence_name(value = nil, &block) #:nodoc:
+ if block
+ ActiveSupport::Deprecation.warn(
+ "Calling set_sequence_name is deprecated. If you need to lazily evaluate " \
+ "the sequence name, define your own `self.sequence_name` class method. You can use `super` " \
+ "to get the default sequence name where you would have called `original_sequence_name`."
+ )
+
+ define_attr_method :sequence_name, value, &block
+ else
+ ActiveSupport::Deprecation.warn(
+ "Calling set_sequence_name is deprecated. Please use `self.sequence_name = 'the_name'` instead."
+ )
+
+ self.sequence_name = value
+ end
end
- alias :sequence_name= :set_sequence_name
# Indicates whether the table associated with this class exists
def table_exists?