Class: Datamappify::Data::Criteria::Relational::Save

Inherits:
Common
  • Object
show all
Defined in:
lib/datamappify/data/criteria/relational/save.rb

Direct Known Subclasses

ActiveRecord::Save, Sequel::Save

Instance Attribute Summary

Attributes inherited from Common

#attributes, #attributes_and_values, #criteria, #entity, #options, #source_class

Instance Method Summary collapse

Methods inherited from Common

#any_attribute, #default_source_class_name, #ignore?, #ignore_attribute?, #initialize, #key_name, #key_value, #new_record?, #perform_with_callbacks, #pk, #primary_record?, #source_class_name, #store_attribute_value

Constructor Details

This class inherits a constructor from Datamappify::Data::Criteria::Common

Instance Method Details

#create_recordObject (private)



12
13
14
15
16
17
18
19
# File 'lib/datamappify/data/criteria/relational/save.rb', line 12

def create_record
  record = source_class.new(criteria)
  saved_record = save(record)

  update_entity_with(saved_record) if primary_record?

  record
end

#performObject



6
7
8
# File 'lib/datamappify/data/criteria/relational/save.rb', line 6

def perform
  new_record? ? create_record : save_record unless ignore?
end

#update_entity_with(record) ⇒ Object (private)



21
22
23
# File 'lib/datamappify/data/criteria/relational/save.rb', line 21

def update_entity_with(record)
  entity.id = record.send(key_name)
end