Module: ActiveRecord::Persistence

Defined in:
lib/composite_primary_keys/persistence.rb

Instance Method Summary collapse

Instance Method Details

#cpk_conditionsObject



3
4
5
6
7
8
9
# File 'lib/composite_primary_keys/persistence.rb', line 3

def cpk_conditions
  if self.composite?
    ids_hash
  else
    self.class.arel_table[self.class.primary_key].eq(id)
  end
end

#destroyObject



11
12
13
14
15
16
17
18
19
# File 'lib/composite_primary_keys/persistence.rb', line 11

def destroy
  if persisted?
    # self.class.unscoped.where(self.class.arel_table[self.class.primary_key].eq(id)).delete_all
    self.class.unscoped.where(cpk_conditions).delete_all
  end

  @destroyed = true
  freeze
end

#update(attribute_names = @attributes.keys) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/composite_primary_keys/persistence.rb', line 21

def update(attribute_names = @attributes.keys)
  attributes_with_values = arel_attributes_values(false, false, attribute_names)
  return 0 if attributes_with_values.empty?
  # CPK
  # self.class.unscoped.where(self.class.arel_table[self.class.primary_key].eq(id)).arel.update(attributes_with_values)
  self.class.unscoped.where(cpk_conditions).arel.update(attributes_with_values)
end