post query builder: fix incompatibilities with Rails 6.1.
* Rename the `#negate` and `#and` methods that we monkey patch into ActiveRecord::Relation. These methods are now defined in Rails 6.1, but they shadow our methods and have slightly different behavior. * Fix a call to `invert`. It no longer accepts an argument.
This commit is contained in:
@@ -10,12 +10,13 @@ module Searchable
|
||||
1 + params.values.map { |v| parameter_hash?(v) ? parameter_depth(v) : 1 }.max
|
||||
end
|
||||
|
||||
def negate(kind = :nand)
|
||||
unscoped.where(all.where_clause.invert(kind).ast)
|
||||
def negate_relation
|
||||
unscoped.where(all.where_clause.invert.ast)
|
||||
end
|
||||
|
||||
# XXX hacky method to AND two relations together.
|
||||
def and(relation)
|
||||
# XXX Replace with ActiveRecord#and (cf https://github.com/rails/rails/pull/39328)
|
||||
def and_relation(relation)
|
||||
q = all
|
||||
q = q.where(relation.where_clause.ast) if relation.where_clause.present?
|
||||
q = q.joins(relation.joins_values + q.joins_values) if relation.joins_values.present?
|
||||
|
||||
@@ -92,8 +92,8 @@ class PostQueryBuilder
|
||||
def metatags_match(metatags, relation)
|
||||
metatags.each do |metatag|
|
||||
clause = metatag_matches(metatag.name, metatag.value, quoted: metatag.quoted)
|
||||
clause = clause.negate if metatag.negated
|
||||
relation = relation.and(clause)
|
||||
clause = clause.negate_relation if metatag.negated
|
||||
relation = relation.and_relation(clause)
|
||||
end
|
||||
|
||||
relation
|
||||
|
||||
Reference in New Issue
Block a user