Sha256: b7942e50b3b2a067abe644f73414ce81634a9ef2786c56b7af6301182badb4c7

Contents?: true

Size: 1.03 KB

Versions: 14

Compression:

Stored size: 1.03 KB

Contents

module ActiveRecord
  module AttributeMethods
    module Write
      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

      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
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
composite_primary_keys-12.0.9 lib/composite_primary_keys/attribute_methods/write.rb
composite_primary_keys-12.0.8 lib/composite_primary_keys/attribute_methods/write.rb
composite_primary_keys-12.0.6 lib/composite_primary_keys/attribute_methods/write.rb
composite_primary_keys-12.0.5 lib/composite_primary_keys/attribute_methods/write.rb
composite_primary_keys-12.0.4 lib/composite_primary_keys/attribute_methods/write.rb
composite_primary_keys-12.0.3 lib/composite_primary_keys/attribute_methods/write.rb
composite_primary_keys-12.0.2 lib/composite_primary_keys/attribute_methods/write.rb
composite_primary_keys-12.0.1 lib/composite_primary_keys/attribute_methods/write.rb
composite_primary_keys-12.0.0 lib/composite_primary_keys/attribute_methods/write.rb
composite_primary_keys-12.0.0.rc5 lib/composite_primary_keys/attribute_methods/write.rb
composite_primary_keys-12.0.0.rc4 lib/composite_primary_keys/attribute_methods/write.rb
composite_primary_keys-12.0.0.rc3 lib/composite_primary_keys/attribute_methods/write.rb
composite_primary_keys-12.0.0.rc2 lib/composite_primary_keys/attribute_methods/write.rb
composite_primary_keys-12.0.0.rc1 lib/composite_primary_keys/attribute_methods/write.rb