diff options
author | Yves Senn <yves.senn@gmail.com> | 2014-06-04 22:20:59 +0200 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2014-06-04 22:22:45 +0200 |
commit | 3036c4031ab0ce2632d6ac1479ab27cdc4bb4941 (patch) | |
tree | 1fc6ec023ab91f35f237052b7565ced6157be8fa /activerecord/lib/active_record | |
parent | 31737e0461640b15ea60960ec24fef7571727831 (diff) | |
download | rails-3036c4031ab0ce2632d6ac1479ab27cdc4bb4941.tar.gz rails-3036c4031ab0ce2632d6ac1479ab27cdc4bb4941.tar.bz2 rails-3036c4031ab0ce2632d6ac1479ab27cdc4bb4941.zip |
have an actual `NullColumn` object and update docs accordingly.
Follow up to #15438 and #15502.
/cc @sgrif
Diffstat (limited to 'activerecord/lib/active_record')
3 files changed, 15 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/attribute_methods.rb b/activerecord/lib/active_record/attribute_methods.rb index dccbd48592..e626227e7e 100644 --- a/activerecord/lib/active_record/attribute_methods.rb +++ b/activerecord/lib/active_record/attribute_methods.rb @@ -195,8 +195,9 @@ module ActiveRecord end end - # Returns the column object for the named attribute. Returns +nil+ if the - # named attribute not exists. + # 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 @@ -206,11 +207,11 @@ module ActiveRecord # # => #<ActiveRecord::ConnectionAdapters::SQLite3Column:0x007ff4ab083980 @name="name", @sql_type="varchar(255)", @null=true, ...> # # person.column_for_attribute(:nothing) - # # => #<ActiveRecord::ConnectionAdapters::Column:0xXXX @name=nil, @sql_type=nil, @cast_type=#<Type::Value>, ...> + # # => #<ActiveRecord::ConnectionAdapters::NullColumn:0xXXX @name=nil, @sql_type=nil, @cast_type=#<Type::Value>, ...> def column_for_attribute(name) name = name.to_s columns_hash.fetch(name) do - ConnectionAdapters::Column.new(name, nil, Type::Value.new) + ConnectionAdapters::NullColumn.new(name) end end end diff --git a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb index b589cfee09..cc494a7f40 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb @@ -14,7 +14,10 @@ module ActiveRecord module ConnectionAdapters # :nodoc: extend ActiveSupport::Autoload - autoload :Column + autoload_at 'active_record/connection_adapters/column' do + autoload :Column + autoload :NullColumn + end autoload :ConnectionSpecification autoload_at 'active_record/connection_adapters/abstract/schema_definitions' do diff --git a/activerecord/lib/active_record/connection_adapters/column.rb b/activerecord/lib/active_record/connection_adapters/column.rb index 3b0dcbc6a7..5e4e00bc64 100644 --- a/activerecord/lib/active_record/connection_adapters/column.rb +++ b/activerecord/lib/active_record/connection_adapters/column.rb @@ -55,6 +55,12 @@ module ActiveRecord type_cast(default) end end + + class NullColumn < Column + def initialize(name) + super name, nil, Type::Value.new + end + end end # :startdoc: end |