Skip to content

Commit

Permalink
use Rails' version unless it applies to CPK
Browse files Browse the repository at this point in the history
  • Loading branch information
codeodor committed Mar 20, 2013
1 parent 600c5e6 commit 430d6a2
Showing 1 changed file with 5 additions and 20 deletions.
25 changes: 5 additions & 20 deletions lib/composite_primary_keys/attribute_methods/dirty.rb
Original file line number Diff line number Diff line change
@@ -1,27 +1,12 @@
module ActiveRecord
module AttributeMethods
module Dirty
alias_method :rails_dirty_write_attribute, :write_attribute
def write_attribute(attr, value)
# CPK
if attr.kind_of?(Array)
# A *composite* attribute can't be marked as changed! So do nothing now.
# We will come back in here with an *individual* attribute when Write#write_attribute looks through the individual attributes comprising this composite key:
# [attr_name, value].transpose.map {|name,val| write_attribute(name, val)}
else
attr = attr.to_s

# The attribute already has an unsaved change.
if attribute_changed?(attr)
old = @changed_attributes[attr]
@changed_attributes.delete(attr) unless _field_changed?(attr, old, value)
else
old = clone_attribute_value(:read_attribute, attr)
@changed_attributes[attr] = old if _field_changed?(attr, old, value)
end
end

# Carry on.
super(attr, value)
# CPK: A *composite* attribute can't be marked as changed! So do nothing now.
# We will come back in here with an *individual* attribute when Write#write_attribute looks through the individual attributes comprising this composite key:
# [attr_name, value].transpose.map {|name,val| write_attribute(name, val)}
rails_dirty_write_attribute(attr, value) unless attr.kind_of?(Array)
end
end
end
Expand Down

0 comments on commit 430d6a2

Please sign in to comment.