aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2011-11-29 15:34:22 +0000
committerJon Leighton <j@jonathanleighton.com>2011-11-29 20:13:36 +0000
commit34609d67b442366644945a95b019daf5b474727b (patch)
tree83172d72312d7f12cdcc99fc9402890879012403 /activerecord/lib/active_record
parent0b72a04d0c93b666c23500aefbe4a6a76593cd36 (diff)
downloadrails-34609d67b442366644945a95b019daf5b474727b.tar.gz
rails-34609d67b442366644945a95b019daf5b474727b.tar.bz2
rails-34609d67b442366644945a95b019daf5b474727b.zip
Deprecate set_inheritance_column in favour of self.inheritance_column=
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/base.rb46
1 files changed, 29 insertions, 17 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index bccf1b9b77..d1d3888de2 100644
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -702,10 +702,36 @@ module ActiveRecord #:nodoc:
(parents.detect{ |p| p.respond_to?(:table_name_prefix) } || self).table_name_prefix
end
- # Defines the column name for use with single table inheritance. Use
- # <tt>set_inheritance_column</tt> to set a different value.
+ # The name of the column containing the object's class when Single Table Inheritance is used
def inheritance_column
- @inheritance_column ||= "type"
+ if self == Base
+ 'type'
+ else
+ defined?(@inheritance_column) ? @inheritance_column : superclass.inheritance_column
+ end
+ end
+
+ # Sets the value of inheritance_column
+ def inheritance_column=(value)
+ @inheritance_column = value.to_s
+ end
+
+ def set_inheritance_column(value = nil, &block) #:nodoc:
+ if block
+ ActiveSupport::Deprecation.warn(
+ "Calling set_inheritance_column is deprecated. If you need to lazily evaluate " \
+ "the inheritance column, define your own `self.inheritance_column` class method. You can use `super` " \
+ "to get the default inheritance column where you would have called `original_inheritance_column`."
+ )
+
+ define_attr_method :inheritance_column, value, &block
+ else
+ ActiveSupport::Deprecation.warn(
+ "Calling set_inheritance_column is deprecated. Please use `self.inheritance_column = 'the_name'` instead."
+ )
+
+ self.inheritance_column = value
+ end
end
# Lazy-set the sequence name to the connection's default. This method
@@ -720,20 +746,6 @@ module ActiveRecord #:nodoc:
default
end
- # Sets the name of the inheritance column to use to the given value,
- # or (if the value # is nil or false) to the value returned by the
- # given block.
- #
- # class Project < ActiveRecord::Base
- # set_inheritance_column do
- # original_inheritance_column + "_id"
- # end
- # end
- def set_inheritance_column(value = nil, &block)
- define_attr_method :inheritance_column, value, &block
- end
- alias :inheritance_column= :set_inheritance_column
-
# Sets the name of the sequence to use when generating ids to the given
# value, or (if the value is nil or false) to the value returned by the
# given block. This is required for Oracle and is useful for any