Method: Sequel::Model::InstanceMethods#pk
- Defined in:
- lib/sequel/model/base.rb
#pk ⇒ Object
Returns the primary key value identifying the model instance. Raises an Error if this model does not have a primary key. If the model has a composite primary key, returns an array of values.
Artist[1].pk # => 1
Artist[[1, 2]].pk # => [1, 2]
1599 1600 1601 1602 1603 1604 1605 1606 1607 |
# File 'lib/sequel/model/base.rb', line 1599 def pk raise(Error, "No primary key is associated with this model") unless key = primary_key if key.is_a?(Array) vals = @values key.map{|k| vals[k]} else @values[key] end end |