Sha256: 177f7a32a2109cf292c839882c8a2fc206904b272e14fd2e971bbca407acd71f

Contents?: true

Size: 906 Bytes

Versions: 8

Compression:

Stored size: 906 Bytes

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:
          value = [nil] * attr.length if value.nil?
          [attr, value].transpose.map {|name,val| write_attribute(name, val)}
        else
          attr = attr.to_s

          old_value = old_attribute_value(attr)

          result = super
          store_original_raw_attribute(attr)
          save_changed_attribute(attr, old_value)
          result
        end
      end
    end
  end
end

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

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
composite_primary_keys-8.1.8 lib/composite_primary_keys/attribute_methods/dirty.rb
composite_primary_keys-8.1.7 lib/composite_primary_keys/attribute_methods/dirty.rb
composite_primary_keys-8.1.6 lib/composite_primary_keys/attribute_methods/dirty.rb
composite_primary_keys-8.1.5 lib/composite_primary_keys/attribute_methods/dirty.rb
composite_primary_keys-8.1.4 lib/composite_primary_keys/attribute_methods/dirty.rb
composite_primary_keys-8.1.3 lib/composite_primary_keys/attribute_methods/dirty.rb
composite_primary_keys-8.1.2 lib/composite_primary_keys/attribute_methods/dirty.rb
composite_primary_keys-8.1.1 lib/composite_primary_keys/attribute_methods/dirty.rb