Sha256: 14a1818726a8a8fb2a08e873edc15cc9a4569f95fc96cbed731d57e7c8c77cfb

Contents?: true

Size: 1.07 KB

Versions: 17

Compression:

Stored size: 1.07 KB

Contents

module ActiveRecord
  module AttributeMethods
    module Dirty
      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)
      end
    end
  end
end

ActiveRecord::Base.class_eval do
  alias :[]= :write_attribute
  public :[]=
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
composite_primary_keys-6.0.8 lib/composite_primary_keys/attribute_methods/dirty.rb
composite_primary_keys-6.0.7 lib/composite_primary_keys/attribute_methods/dirty.rb
composite_primary_keys-7.0.9 lib/composite_primary_keys/attribute_methods/dirty.rb
composite_primary_keys-7.0.8 lib/composite_primary_keys/attribute_methods/dirty.rb
composite_primary_keys-7.0.7 lib/composite_primary_keys/attribute_methods/dirty.rb
composite_primary_keys-7.0.6 lib/composite_primary_keys/attribute_methods/dirty.rb
composite_primary_keys-7.0.5 lib/composite_primary_keys/attribute_methods/dirty.rb
composite_primary_keys-7.0.4 lib/composite_primary_keys/attribute_methods/dirty.rb
composite_primary_keys-7.0.3 lib/composite_primary_keys/attribute_methods/dirty.rb
composite_primary_keys-7.0.2 lib/composite_primary_keys/attribute_methods/dirty.rb
composite_primary_keys-7.0.1 lib/composite_primary_keys/attribute_methods/dirty.rb
composite_primary_keys-7.0.0 lib/composite_primary_keys/attribute_methods/dirty.rb
composite_primary_keys-6.0.6 lib/composite_primary_keys/attribute_methods/dirty.rb
composite_primary_keys-6.0.5 lib/composite_primary_keys/attribute_methods/dirty.rb
composite_primary_keys-6.0.3 lib/composite_primary_keys/attribute_methods/dirty.rb
composite_primary_keys-6.0.1 lib/composite_primary_keys/attribute_methods/dirty.rb
composite_primary_keys-6.0.0 lib/composite_primary_keys/attribute_methods/dirty.rb