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:
evazion
2020-12-13 04:02:25 -06:00
parent 8d87b1a0c0
commit 35134abe8f
2 changed files with 6 additions and 5 deletions

View File

@@ -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?

View File

@@ -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