lib/ransack/adapters/active_record/context.rb
def build_correlated_subquery(association)
          join_constraints = extract_joins(association)
          join_root = join_constraints.shift
          join_table = join_root.left
          correlated_key = join_root.right.expr.left
          subquery = Arel::SelectManager.new(association.base_klass)
          subquery.from(join_root.left)
          subquery.project(correlated_key)
          join_constraints.each do |j|
            subquery.join_sources << Arel::Nodes::InnerJoin.new(j.left, j.right)
          end
          subquery.where(correlated_key.eq(primary_key))
        end
# Build an Arel subquery that selects keys for the top query,
# drawn from the first join association's foreign_key.
#
# Example: for an Article that has_and_belongs_to_many Tags
#
#   context = Article.search.context
#   attribute = Attribute.new(context, "tags_name").tap do |a|
#     context.bind(a, a.name)
#   end
#   context.build_correlated_subquery(attribute.parent).to_sql
#
#   # SELECT "articles_tags"."article_id" FROM "articles_tags"
#   # INNER JOIN "tags" ON "tags"."id" = "articles_tags"."tag_id"
#   # WHERE "articles_tags"."article_id" = "articles"."id"
#
# The WHERE condition on this query makes it invalid by itself,
# because it is correlated to the primary key on the outer query.
#
Build an Arel subquery that selects keys for the top query,
drawn from the first join association's foreign_key.

for an Article that has_and_belongs_to_many Tags





The WHERE condition on this query makes it invalid by itself,
because it is correlated to the primary key on the outer query.
Build an Arel subquery that selects keys for the top query drawn from the first join association ' s foreign_key . for an Article that has_and_belongs_to_many Tags The WHERE condition on this query makes it invalid by itself because it is correlated to the primary key on the outer query .
def build_correlated_subquery(association)
          join_constraints = extract_joins(association)
          join_root = join_constraints.shift
          join_table = join_root.left
          correlated_key = join_root.right.expr.left
          subquery = Arel::SelectManager.new(association.base_klass)
          subquery.from(join_root.left)
          subquery.project(correlated_key)
          join_constraints.each do |j|
            subquery.join_sources << Arel::Nodes::InnerJoin.new(j.left, j.right)
          end
          subquery.where(correlated_key.eq(primary_key))
        end
def build_correlated_subquery ( association ) join_constraints = extract_joins ( association ) join_root = join_constraints . shift join_table = join_root . left correlated_key = join_root . right . expr . left subquery = Arel :: SelectManager . new ( association . base_klass ) subquery . from ( join_root . left ) subquery . project ( correlated_key ) join_constraints . each do | j | subquery . join_sources << Arel :: Nodes :: InnerJoin . new ( j . left , j . right ) end subquery . where ( correlated_key . eq ( primary_key ) ) end
Build an Arel subquery that selects keys for the top query,
drawn from the first join association's foreign_key.
Build an Arel subquery that selects keys for the top query drawn from the first join association ' s foreign_key .
association