Sha256: 9fd4472b7b8711c20e5d930d93c77bdfecfc74823336c01b3f6c8e498fee6c3c

Contents?: true

Size: 793 Bytes

Versions: 17

Compression:

Stored size: 793 Bytes

Contents

module CompositePrimaryKeys
  module CompositeRelation
    include CompositePrimaryKeys::ActiveRecord::Batches
    include CompositePrimaryKeys::ActiveRecord::Calculations
    include CompositePrimaryKeys::ActiveRecord::FinderMethods
    include CompositePrimaryKeys::ActiveRecord::QueryMethods

    def destroy(id_or_array)
      # Without CPK:
      #if id.is_a?(Array)
      #  id.map { |one_id| destroy(one_id) }
      #else
      #  find(id).destroy
      #end

      id_or_array = if id_or_array.kind_of?(CompositePrimaryKeys::CompositeKeys)
        [id_or_array]
      else
        Array(id_or_array)
      end

      id_or_array.each do |id|
        where(cpk_id_predicate(table, self.primary_key, id)).each do |record|
          record.destroy
        end
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
composite_primary_keys-14.0.9 lib/composite_primary_keys/composite_relation.rb
composite_primary_keys-14.0.8 lib/composite_primary_keys/composite_relation.rb
composite_primary_keys-13.0.8 lib/composite_primary_keys/composite_relation.rb
composite_primary_keys-14.0.7 lib/composite_primary_keys/composite_relation.rb
composite_primary_keys-14.0.6 lib/composite_primary_keys/composite_relation.rb
composite_primary_keys-13.0.7 lib/composite_primary_keys/composite_relation.rb
composite_primary_keys-13.0.6 lib/composite_primary_keys/composite_relation.rb
composite_primary_keys-14.0.5 lib/composite_primary_keys/composite_relation.rb
composite_primary_keys-13.0.5 lib/composite_primary_keys/composite_relation.rb
composite_primary_keys-13.0.4 lib/composite_primary_keys/composite_relation.rb
composite_primary_keys-14.0.4 lib/composite_primary_keys/composite_relation.rb
composite_primary_keys-14.0.3 lib/composite_primary_keys/composite_relation.rb
composite_primary_keys-13.0.3 lib/composite_primary_keys/composite_relation.rb
composite_primary_keys-14.0.2 lib/composite_primary_keys/composite_relation.rb
composite_primary_keys-13.0.2 lib/composite_primary_keys/composite_relation.rb
composite_primary_keys-14.0.1 lib/composite_primary_keys/composite_relation.rb
composite_primary_keys-11.0.0.rc2 lib/composite_primary_keys/composite_relation.rb