Sha256: 51c1a6aae3eb33a942eac0adbc54d9b560e7d4bcefbf68fc95da74023b0d5199

Contents?: true

Size: 1.04 KB

Versions: 11

Compression:

Stored size: 1.04 KB

Contents

module ActiveRecord
  class PredicateBuilder
    silence_warnings do
      def expand(column, value)
        # Find the foreign key when using queries such as:
        # Post.where(author: author)
        #
        # For polymorphic relationships, find the foreign key and type:
        # PriceEstimate.where(estimate_of: treasure)

        # CPK
        if Base === Array(value).first && Array(value).first.composite? && reflection = table.associated_with?(column)
          columns = reflection.foreign_key
          values = Array(value).map{|v| columns.map{|c| v.public_send(c) }}
          cpk_predicate_builder = Class.new.extend(CompositePrimaryKeys::Predicates)
          predicate = cpk_predicate_builder.cpk_in_predicate(table.send(:arel_table), columns, values)
          return predicate
        else
          # Original code
          value = AssociationQueryHandler.value_for(table, column, value) if table.associated_with?(column)
          build(table.arel_attribute(column), value)
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
composite_primary_keys-9.0.10 lib/composite_primary_keys/relation/predicate_builder.rb
composite_primary_keys-9.0.9 lib/composite_primary_keys/relation/predicate_builder.rb
composite_primary_keys-9.0.8 lib/composite_primary_keys/relation/predicate_builder.rb
composite_primary_keys-9.0.7 lib/composite_primary_keys/relation/predicate_builder.rb
composite_primary_keys-9.0.6 lib/composite_primary_keys/relation/predicate_builder.rb
composite_primary_keys-9.0.5 lib/composite_primary_keys/relation/predicate_builder.rb
composite_primary_keys-9.0.4 lib/composite_primary_keys/relation/predicate_builder.rb
composite_primary_keys-9.0.2 lib/composite_primary_keys/relation/predicate_builder.rb
composite_primary_keys-9.0.1 lib/composite_primary_keys/relation/predicate_builder.rb
composite_primary_keys-9.0.0 lib/composite_primary_keys/relation/predicate_builder.rb
composite_primary_keys-9.0.0.beta1 lib/composite_primary_keys/relation/predicate_builder.rb