Module: Datamappify::Data::Criteria::Concerns::UpdatePrimaryRecord

Included in:
ActiveRecord::Save, Sequel::Save
Defined in:
lib/datamappify/data/criteria/concerns/update_primary_record.rb

Instance Method Summary collapse

Instance Method Details

#save(record) ⇒ Object (private)



8
9
10
11
12
13
14
# File 'lib/datamappify/data/criteria/concerns/update_primary_record.rb', line 8

def save(record)
  if options && options[:via] && options[:primary_record]
    update_primary_record_with(record)
  end

  record
end

#update_primary_record_with(record) ⇒ Object (private)



16
17
18
19
20
21
22
23
# File 'lib/datamappify/data/criteria/concerns/update_primary_record.rb', line 16

def update_primary_record_with(record)
  save = self.class.superclass.new(options[:primary_record].class, entity, {
    :id => options[:primary_record].id
  })

  save.attributes_and_values = { options[:via] => record.id }
  save.send(:save_record)
end