Active Record Attribute Methods Primary Key
- I
- T
Instance Public methods
id() Link
Returns the primary key column’s value.
Source: show
# File activerecord/lib/active_record/attribute_methods/primary_key.rb, line 19 def id return _read_attribute(@primary_key) unless @primary_key.is_a?(Array) @primary_key.map { |pk| _read_attribute(pk) } end
id=(value) Link
Sets the primary key column’s value.
Source: show
# File activerecord/lib/active_record/attribute_methods/primary_key.rb, line 32 def id=(value) if self.class.composite_primary_key? @primary_key.zip(value) { |attr, value| _write_attribute(attr, value) } else _write_attribute(@primary_key, value) end end
id?() Link
Queries the primary key column’s value.
Source: show
# File activerecord/lib/active_record/attribute_methods/primary_key.rb, line 41 def id? if self.class.composite_primary_key? @primary_key.all? { |col| query_attribute(col) } else query_attribute(@primary_key) end end
id_before_type_cast() Link
Returns the primary key column’s value before type cast.
Source: show
# File activerecord/lib/active_record/attribute_methods/primary_key.rb, line 50 def id_before_type_cast if self.class.composite_primary_key? @primary_key.map { |col| attribute_before_type_cast(col) } else attribute_before_type_cast(@primary_key) end end
id_in_database() Link
Returns the primary key column’s value from the database.
Source: show
# File activerecord/lib/active_record/attribute_methods/primary_key.rb, line 68 def id_in_database if self.class.composite_primary_key? @primary_key.map { |col| attribute_in_database(col) } else attribute_in_database(@primary_key) end end