Module: ActiveRecord::AttributeMethods::PrimaryKey

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

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#id_in_databaseObject



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/composite_primary_keys/attribute_methods/primary_key.rb', line 30

def id_in_database
  # 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.



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

def id_was
  # 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