diff --git a/activerecord/lib/active_record/attribute_methods.rb b/activerecord/lib/active_record/attribute_methods.rb index e11d0fce8f..1ee16831f0 100644 --- a/activerecord/lib/active_record/attribute_methods.rb +++ b/activerecord/lib/active_record/attribute_methods.rb @@ -19,8 +19,6 @@ module ActiveRecord include TimeZoneConversion include Dirty include Serialization - - delegate :column_for_attribute, to: :class end RESTRICTED_CLASS_METHODS = %w(private public protected allocate new name parent superclass) @@ -188,26 +186,6 @@ module ActiveRecord def _has_attribute?(attr_name) # :nodoc: attribute_types.key?(attr_name) end - - # Returns the column object for the named attribute. - # Returns a +ActiveRecord::ConnectionAdapters::NullColumn+ if the - # named attribute does not exist. - # - # class Person < ActiveRecord::Base - # end - # - # person = Person.new - # person.column_for_attribute(:name) # the result depends on the ConnectionAdapter - # # => # - # - # person.column_for_attribute(:nothing) - # # => #, ...> - def column_for_attribute(name) - name = name.to_s - columns_hash.fetch(name) do - ConnectionAdapters::NullColumn.new(name) - end - end end # A Person object with a name attribute can ask person.respond_to?(:name), diff --git a/activerecord/lib/active_record/model_schema.rb b/activerecord/lib/active_record/model_schema.rb index 3159483bae..61da9fdd32 100644 --- a/activerecord/lib/active_record/model_schema.rb +++ b/activerecord/lib/active_record/model_schema.rb @@ -141,7 +141,7 @@ module ActiveRecord self.inheritance_column = "type" self.ignored_columns = [].freeze - delegate :type_for_attribute, to: :class + delegate :type_for_attribute, :column_for_attribute, to: :class initialize_load_schema_monitor end @@ -400,6 +400,26 @@ module ActiveRecord end end + # Returns the column object for the named attribute. + # Returns a +ActiveRecord::ConnectionAdapters::NullColumn+ if the + # named attribute does not exist. + # + # class Person < ActiveRecord::Base + # end + # + # person = Person.new + # person.column_for_attribute(:name) # the result depends on the ConnectionAdapter + # # => # + # + # person.column_for_attribute(:nothing) + # # => #, ...> + def column_for_attribute(name) + name = name.to_s + columns_hash.fetch(name) do + ConnectionAdapters::NullColumn.new(name) + end + end + # Returns a hash where the keys are column names and the values are # default values when instantiating the Active Record object for this table. def column_defaults