Sha256: 3e30786dc189cd3218391fc66418d5e160c36a48c8e5b2df7496babc6a99227f

Contents?: true

Size: 1.13 KB

Versions: 7

Compression:

Stored size: 1.13 KB

Contents

module ActiveRecord
  class PredicateBuilder
    def self.expand(klass, table, column, value)
      queries = []

      # 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)
      if klass && reflection = klass._reflect_on_association(column)
        base_class = polymorphic_base_class_from_value(value)

        if reflection.polymorphic? && base_class
          queries << build(table[reflection.foreign_type], base_class)
        end

        column = reflection.foreign_key

        # CPK
        # if base_class
        if base_class && !(Base === value && value.composite?)
          primary_key = reflection.association_primary_key(base_class)
          value = convert_value_to_association_ids(value, primary_key)
        end
      end

      #CPK
      if Base === value && value.composite?
        queries << cpk_id_predicate(table, column, value.id)
      else
        queries << build(table[column], value)
      end
      queries
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
composite_primary_keys-8.1.8 lib/composite_primary_keys/relation/predicate_builder.rb
composite_primary_keys-8.1.7 lib/composite_primary_keys/relation/predicate_builder.rb
composite_primary_keys-8.1.6 lib/composite_primary_keys/relation/predicate_builder.rb
composite_primary_keys-8.1.5 lib/composite_primary_keys/relation/predicate_builder.rb
composite_primary_keys-8.1.4 lib/composite_primary_keys/relation/predicate_builder.rb
composite_primary_keys-8.1.3 lib/composite_primary_keys/relation/predicate_builder.rb
composite_primary_keys-8.1.2 lib/composite_primary_keys/relation/predicate_builder.rb