Sha256: bf4d659c011459067f7cbad74c28d0d87fde238ae4fe3993d676e41194b69c58

Contents?: true

Size: 701 Bytes

Versions: 6

Compression:

Stored size: 701 Bytes

Contents

module ActiveModel
  module AttributeAssignment
    def _assign_attribute(k, v)
      # CPK. This is super ugly, but if a table has a composite key where one of the fields is named :id we need
      # to handle it as a single value. Otherwise, we would call the id=(value) method which is expecting
      # and array of values.
      if k == 'id' && self.kind_of?(ActiveRecord::Base) && self.composite? && !self.column_for_attribute(k).null
        self._write_attribute(k, v)
      else
        setter = :"#{k}="
        if respond_to?(setter)
          public_send(setter, v)
        else
          raise UnknownAttributeError.new(self, k)
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
composite_primary_keys-12.0.9 lib/composite_primary_keys/active_model/attribute_assignment.rb
composite_primary_keys-12.0.8 lib/composite_primary_keys/active_model/attribute_assignment.rb
composite_primary_keys-12.0.6 lib/composite_primary_keys/active_model/attribute_assignment.rb
composite_primary_keys-12.0.5 lib/composite_primary_keys/active_model/attribute_assignment.rb
composite_primary_keys-12.0.4 lib/composite_primary_keys/active_model/attribute_assignment.rb
composite_primary_keys-12.0.3 lib/composite_primary_keys/active_model/attribute_assignment.rb