instance method column_for_attribute

Ruby on Rails 4.1.16

Since v4.0.13 Last seen in v4.1.16

Available in: v4.0.13 v4.1.16

Signature

column_for_attribute(name)

Returns the column object for the named attribute. Returns nil if the named attribute not exists.

class Person < ActiveRecord::Base
end

person = Person.new
person.column_for_attribute(:name) # the result depends on the ConnectionAdapter
# => #<ActiveRecord::ConnectionAdapters::SQLite3Column:0x007ff4ab083980 @name="name", @sql_type="varchar(255)", @null=true, ...>

person.column_for_attribute(:nothing)
# => nil

Parameters

name req
Source
# File activerecord/lib/active_record/attribute_methods.rb, line 360
    def column_for_attribute(name)
      # FIXME: should this return a null object for columns that don't exist?
      self.class.columns_hash[name.to_s]
    end

Defined in activerecord/lib/active_record/attribute_methods.rb line 360 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActiveRecord::AttributeMethods

Type at least 2 characters to search.

↑↓ navigate · open · esc close