Module: ActiveRecord::AttributeMethods::PrimaryKey

Defined in:
lib/composite_primary_keys/attribute_methods/primary_key.rb

Instance Method Summary collapse

Instance Method Details

#id_in_databaseObject



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/composite_primary_keys/attribute_methods/primary_key.rb', line 18

def id_in_database
  sync_with_transaction_state
  # CPK
  # attribute_in_database(self.class.primary_key)
  if self.composite?
    self.class.primary_keys.map do |key_attr|
      attribute_in_database(key_attr)
    end
  else
    attribute_in_database(self.class.primary_key)
  end
end

#id_wasObject

Returns the primary key previous value.



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/composite_primary_keys/attribute_methods/primary_key.rb', line 5

def id_was
  sync_with_transaction_state
  # CPK
  # attribute_was(self.class.primary_key)
  if self.composite?
    self.class.primary_keys.map do |key_attr|
      attribute_changed?(key_attr) ? changed_attributes[key_attr] : self.ids_hash[key_attr]
    end
  else
    attribute_was(self.class.primary_key)
  end
end