Module: Cuprum::Collections::Relation::PrimaryKeys

Included in:
Collection, Cuprum::Collections::Resource
Defined in:
lib/cuprum/collections/relation.rb

Overview

Methods for specifying a relation’s primary key.

Instance Method Summary collapse

Instance Method Details

#primary_key_nameString

Returns the name of the primary key attribute. Defaults to ‘id’.

Returns:

  • (String)

    the name of the primary key attribute. Defaults to ‘id’.



339
340
341
# File 'lib/cuprum/collections/relation.rb', line 339

def primary_key_name
  @primary_key_name ||= options.fetch(:primary_key_name, 'id').to_s
end

#primary_key_typeClass, Stannum::Constraint

Returns the type of the primary key attribute. Defaults to Integer.

Returns:

  • (Class, Stannum::Constraint)

    the type of the primary key attribute. Defaults to Integer.



345
346
347
348
349
350
# File 'lib/cuprum/collections/relation.rb', line 345

def primary_key_type
  @primary_key_type ||=
    options
      .fetch(:primary_key_type, Integer)
      .then { |obj| obj.is_a?(String) ? Object.const_get(obj) : obj }
end