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:



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/composite_primary_keys/persistence.rb', line 60

def _create_record(attribute_names = self.attribute_names)
  attribute_names &= self.class.column_names
  attributes_values = attributes_with_values_for_create(attribute_names)

  new_id = self.class._insert_record(attributes_values)

  # CPK
  if self.composite? && self.id.compact.empty?
    self.id = new_id
  else
    self.id ||= new_id if self.class.primary_key
  end

  @new_record = false

  yield(self) if block_given?

  id
end