Sha256: fab9718ac6c0401ad3413af678b7463d9c9a93fde9550136c624509a7e22283d

Contents?: true

Size: 1.1 KB

Versions: 11

Compression:

Stored size: 1.1 KB

Contents

module ActiveRecord
  module AttributeMethods
    module Write
      silence_warnings do
        def write_attribute_with_type_cast(attr_name, value, should_type_cast)
          # CPK
          if attr_name.kind_of?(Array)
            value = [nil]*attr_name.length if value.nil?
            unless value.length == attr_name.length
              raise "Number of attr_names #{attr_name.inspect} and values #{value.inspect} do not match"
            end
            [attr_name, value].transpose.map {|name,val| write_attribute(name, val)}
            value
          else
            attr_name = attr_name.to_s
            # CPK
            # attr_name = self.class.primary_key if attr_name == 'id' && self.class.primary_key
            attr_name = self.class.primary_key if attr_name == 'id' && self.class.primary_key && !self.composite?

            if should_type_cast
              @attributes.write_from_user(attr_name, value)
            else
              @attributes.write_cast_value(attr_name, value)
            end

            value
          end
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
composite_primary_keys-9.0.10 lib/composite_primary_keys/attribute_methods/write.rb
composite_primary_keys-9.0.9 lib/composite_primary_keys/attribute_methods/write.rb
composite_primary_keys-9.0.8 lib/composite_primary_keys/attribute_methods/write.rb
composite_primary_keys-9.0.7 lib/composite_primary_keys/attribute_methods/write.rb
composite_primary_keys-9.0.6 lib/composite_primary_keys/attribute_methods/write.rb
composite_primary_keys-9.0.5 lib/composite_primary_keys/attribute_methods/write.rb
composite_primary_keys-9.0.4 lib/composite_primary_keys/attribute_methods/write.rb
composite_primary_keys-9.0.2 lib/composite_primary_keys/attribute_methods/write.rb
composite_primary_keys-9.0.1 lib/composite_primary_keys/attribute_methods/write.rb
composite_primary_keys-9.0.0 lib/composite_primary_keys/attribute_methods/write.rb
composite_primary_keys-9.0.0.beta1 lib/composite_primary_keys/attribute_methods/write.rb