Module: ActiveRecord::AttributeMethods::Write
Relationships & Source Files | |
Namespace Children | |
Modules:
| |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
::ActiveSupport::Concern
|
|
Defined in: | activerecord/lib/active_record/attribute_methods/write.rb |
Class Method Summary
::ActiveSupport::Concern
- Extended
class_methods | Define class methods from given block. |
included | Evaluate given block in context of base class, so that you can write class macros here. |
prepended | Evaluate given block in context of base class, so that you can write class macros here. |
append_features, prepend_features |
Instance Method Summary
-
#write_attribute(attr_name, value)
Updates the attribute identified by
attr_name
using the specifiedvalue
. -
#attribute=(attr_name, value)
private
Alias for #_write_attribute.
-
#_write_attribute(attr_name, value)
(also: #attribute=)
Internal use only
This method exists to avoid the expensive primary_key check internally, without breaking compatibility with the write_attribute API.
DSL Calls
included
[ GitHub ]9 10 11
# File 'activerecord/lib/active_record/attribute_methods/write.rb', line 9
included do attribute_method_suffix "=", parameters: "value" end
Instance Method Details
#_write_attribute(attr_name, value) Also known as: #attribute=
This method is for internal use only.
This method exists to avoid the expensive primary_key check internally, without breaking compatibility with the write_attribute API
# File 'activerecord/lib/active_record/attribute_methods/write.rb', line 41
def _write_attribute(attr_name, value) # :nodoc: @attributes.write_from_user(attr_name, value) end
#attribute=(attr_name, value) (private)
Alias for #_write_attribute.
# File 'activerecord/lib/active_record/attribute_methods/write.rb', line 45
alias :attribute= :_write_attribute
#write_attribute(attr_name, value)
Updates the attribute identified by attr_name
using the specified value
. The attribute value will be type cast upon being read.
# File 'activerecord/lib/active_record/attribute_methods/write.rb', line 31
def write_attribute(attr_name, value) name = attr_name.to_s name = self.class.attribute_aliases[name] || name name = @primary_key if name == "id" && @primary_key @attributes.write_from_user(name, value) end