Module: ActiveRecord

Defined in:
lib/active_record_extended/patch/5_0/predicate_builder_decorator.rb,
lib/active_record_extended/query_methods/where_chain.rb

Overview

Stripped from Rails 5.1.x This patch is used so that when querying with hash elements that do not belong to an association, but instead a data attribute. It returns the corrected attribute binds back to the query builder.

Without joins Before:

Person.where.contains(data: { nickname: "george" })
  #=> "SELECT \"people\".* FROM \"people\" WHERE (\"data\".\"nickname\" @> 'george')"

After:

Person.where.contains(data: { nickname: "george" })
 #=> "SELECT \"people\".* FROM \"people\" WHERE (\"people\".\"data\" @> '\"nickname\"=>\"george\"')"

With Joins Before:

Tag.joins(:person).where.contains(people: { data: { nickname: "george" } })
#=> NoMethodError: undefined method `type' for nil:NilClass

After:

Tag.joins(:person).where.contains(people: { data: { nickname: "george" } })
#=> "SELECT \"tags\".* FROM \"tags\" INNER JOIN \"people\" ON \"people\".\"id\" = \"tags\".\"person_id\"
       WHERE (\"people\".\"data\" @> '\"nickname\"=>\"george\"')"

Defined Under Namespace

Modules: QueryMethods Classes: PredicateBuilder, TableMetadata