Module: ActiveRecord::Persistence

Defined in:
lib/patches/active_record/persistence.rb

Instance Method Summary collapse

Instance Method Details

#_create_record(attribute_names = self.attribute_names) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/patches/active_record/persistence.rb', line 15

def _create_record(attribute_names = self.attribute_names)
  attribute_names_without_translated = attribute_names.select{ |k| not respond_to?('translated?') or not translated?(k) }
  attributes_values = arel_attributes_with_values_for_create(attribute_names_without_translated)

  new_id = self.class.unscoped.insert attributes_values
  self.id ||= new_id if self.class.primary_key

  @new_record = false
  id
end

#_update_record(attribute_names = self.attribute_names) ⇒ Object

Updates the associated record with values matching those of the instance attributes. Returns the number of affected rows.



5
6
7
8
9
10
11
12
13
# File 'lib/patches/active_record/persistence.rb', line 5

def _update_record(attribute_names = self.attribute_names)
  attribute_names_without_translated = attribute_names.select{ |k| not respond_to?('translated?') or not translated?(k) }
  attributes_values = arel_attributes_with_values_for_update(attribute_names_without_translated)
  if attributes_values.empty?
    0
  else
    self.class.unscoped._update_record attributes_values, id, id_was
  end
end