Sha256: ea86cc08001614cdafc9726e712a335787fa199e2911a0c2f7245f3234c154b4

Contents?: true

Size: 880 Bytes

Versions: 2

Compression:

Stored size: 880 Bytes

Contents

module ActiveRecord
  module Associations
    class HasManyAssociation
      silence_warnings do
        def delete_count(method, scope)
          if method == :delete_all
            scope.delete_all
          else
            # CPK
            # scope.update_all(reflection.foreign_key => nil)
            conds = Array(reflection.foreign_key).inject(Hash.new) do |mem, key|
              mem[key] = nil
              mem
            end
            scope.update_all(conds)
          end
        end

        def foreign_key_present?
          if reflection.klass.primary_key
            # CPK
            # owner.attribute_present?(reflection.association_primary_key)
            Array(reflection.klass.primary_key).all? {|key| owner.attribute_present?(key)}
          else
            false
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
composite_primary_keys-9.0.0 lib/composite_primary_keys/associations/has_many_association.rb
composite_primary_keys-9.0.0.beta1 lib/composite_primary_keys/associations/has_many_association.rb