跳至内容 跳至搜索

Active Record 属性方法 主键

命名空间
方法
I
T

实例公共方法

id()

返回主键列的值。如果主键是复合的,则返回主键列值的数组。

# File activerecord/lib/active_record/attribute_methods/primary_key.rb, line 18
def id
  _read_attribute(@primary_key)
end

id=(value)

设置主键列的值。如果主键是复合的,当设置的值不可枚举时,将引发 TypeError。

# File activerecord/lib/active_record/attribute_methods/primary_key.rb, line 28
def id=(value)
  _write_attribute(@primary_key, value)
end

id?()

查询主键列的值。如果主键是复合的,则所有主键列值都必须可查询。

# File activerecord/lib/active_record/attribute_methods/primary_key.rb, line 34
def id?
  _query_attribute(@primary_key)
end

id_before_type_cast()

返回类型转换前的主键列值。如果主键是复合的,则返回类型转换前的主键列值的数组。

# File activerecord/lib/active_record/attribute_methods/primary_key.rb, line 40
def id_before_type_cast
  attribute_before_type_cast(@primary_key)
end

id_in_database()

从数据库返回主键列的值。如果主键是复合的,则返回数据库主键列值的数组。

# File activerecord/lib/active_record/attribute_methods/primary_key.rb, line 52
def id_in_database
  attribute_in_database(@primary_key)
end

id_was()

返回主键列的先前值。如果主键是复合的,则返回主键列先前值的数组。

# File activerecord/lib/active_record/attribute_methods/primary_key.rb, line 46
def id_was
  attribute_was(@primary_key)
end

to_key()

如果可用,则返回此记录的主键值,并将其包装在数组中。

# File activerecord/lib/active_record/attribute_methods/primary_key.rb, line 11
def to_key
  key = id
  Array(key) if key
end