Flowdock
method

expand

Importance_0
Ruby on Rails latest stable (v4.2.1) - 0 notes - Class: ActiveRecord::PredicateBuilder
expand(klass, table, column, value) public

No documentation

This method has no description. You can help the Ruby on Rails community by adding new notes.

Hide source
# File activerecord/lib/active_record/relation/predicate_builder.rb, line 50
    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

        if base_class
          primary_key = reflection.association_primary_key(base_class)
          value = convert_value_to_association_ids(value, primary_key)
        end
      end

      queries << build(table[column], value)
      queries
    end
Register or log in to add new notes.