Module: ActiveRecord::Persistence

Defined in:
lib/composite_primary_keys/persistence.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#_create_record(attribute_names = self.attribute_names) {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/composite_primary_keys/persistence.rb', line 74

def _create_record(attribute_names = self.attribute_names)
  attribute_names = attributes_for_create(attribute_names)

  new_id = self.class._insert_record(
      attributes_with_values(attribute_names)
  )

  # CPK
  if self.composite?
    self.id = self.id.zip(Array(new_id)).map {|id1, id2| id2.nil? ? id1 : id2}
  else
    self.id ||= new_id if self.class.primary_key
  end

  @new_record = false
  @previously_new_record = true

  yield(self) if block_given?

  id
end