Module: ActiveRecord::AttributeMethods::Write

Defined in:
lib/composite_primary_keys/attribute_methods/write.rb

Instance Method Summary collapse

Instance Method Details

#_write_attribute(attr_name, value) ⇒ Object

:nodoc:



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/composite_primary_keys/attribute_methods/write.rb', line 20

def _write_attribute(attr_name, value) # :nodoc:
  # CPK
  if attr_name.kind_of?(Array)
    attr_name.each_with_index do |attr_child_name, i|
      child_value = value ? value[i] : value
      @attributes.write_from_user(attr_child_name.to_s, child_value)
    end
  else
    @attributes.write_from_user(attr_name.to_s, value)
  end

  value
end

#write_attribute(attr_name, value) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/composite_primary_keys/attribute_methods/write.rb', line 4

def write_attribute(attr_name, value)
  # CPK
  #name = attr_name.to_s
  name = attr_name
  if self.class.attribute_alias?(name)
    name = self.class.attribute_alias(name)
  end

  primary_key = self.class.primary_key
  # CPK
  # name = primary_key if name == "id" && primary_key
  name = primary_key if name == "id" && primary_key && !composite?
  sync_with_transaction_state if name == primary_key
  _write_attribute(name, value)
end