target_conditions (DataMapper::Query)

    # File lib/dm-core/query.rb, line 49
        def self.target_conditions(source, source_key, target_key)
          source_values = []

          if source.nil?
            source_values << [ nil ] * target_key.size
          else
            Array(source).each do |resource|
              next unless source_key.loaded?(resource)
              source_values << source_key.get!(resource)
            end
          end

          source_values.uniq!

          if target_key.size == 1
            target_key = target_key.first
            source_values.flatten!

            if source_values.size == 1
              Conditions::EqualToComparison.new(target_key, source_values.first)
            else
              Conditions::InclusionComparison.new(target_key, source_values)
            end
          else
            or_operation = Conditions::OrOperation.new

            source_values.each do |source_value|
              and_operation = Conditions::AndOperation.new

              target_key.zip(source_value) do |property, value|
                and_operation << Conditions::EqualToComparison.new(property, value)
              end

              or_operation << and_operation
            end

            or_operation
          end
        end