Sha256: a207266c245be95d58a92ecb0580dc3d69afb719a44503a62800730da56aa118

Contents?: true

Size: 801 Bytes

Versions: 3

Compression:

Stored size: 801 Bytes

Contents

module ActiveRecord
  module Associations
    module ThroughAssociation
      alias :original_construct_join_attributes :construct_join_attributes

      def construct_join_attributes(*records)
        # CPK
        is_composite = self.source_reflection.polymorphic? ? source_reflection.active_record.composite? : source_reflection.klass.composite?
        if is_composite
          ensure_mutable

          ids = records.map do |record|
            source_reflection.association_primary_key(reflection.klass).map do |key|
              record.send(key)
            end
          end

          cpk_in_predicate(through_association.scope.klass.arel_table, source_reflection.foreign_key, ids)
        else
          original_construct_join_attributes(*records)
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
composite_primary_keys-14.0.2 lib/composite_primary_keys/associations/through_association.rb
composite_primary_keys-13.0.2 lib/composite_primary_keys/associations/through_association.rb
composite_primary_keys-14.0.1 lib/composite_primary_keys/associations/through_association.rb