Module: Dynomite::Item::PrimaryKey

Extended by:
ActiveSupport::Concern
Defined in:
lib/dynomite/item/primary_key.rb

Instance Method Summary collapse

Instance Method Details

#check_primary_key_changed!Object



14
15
16
17
18
19
# File 'lib/dynomite/item/primary_key.rb', line 14

def check_primary_key_changed!
  if primary_key_changed?
    changed_primary_keys = changed & primary_key_fields
    raise Dynomite::Error::PrimaryKeyChangedError, "Cannot change the primary key of an existing record: #{changed_primary_keys}"
  end
end

#partition_keyObject Also known as: hash_key



21
22
23
# File 'lib/dynomite/item/primary_key.rb', line 21

def partition_key
  send(partition_key_field) if partition_key_field
end

#primary_keyObject

Example: “books”, sku: “302”



32
33
34
35
36
37
# File 'lib/dynomite/item/primary_key.rb', line 32

def primary_key
  primary_key = {}
  primary_key[partition_key_field.to_sym] = partition_key
  primary_key[sort_key_field.to_sym] = sort_key if sort_key_field
  primary_key
end

#primary_key_changed?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/dynomite/item/primary_key.rb', line 39

def primary_key_changed?
  !(changed & primary_key_fields).empty?
end

#sort_keyObject Also known as: range_key



26
27
28
# File 'lib/dynomite/item/primary_key.rb', line 26

def sort_key
  send(sort_key_field) if sort_key_field
end