Class: ActiveRecord::Relation::WhereClause

Inherits:
Object
  • Object
show all
Defined in:
lib/arel_extensions.rb

Instance Method Summary collapse

Instance Method Details

#except_predicates(columns) ⇒ Object



328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
# File 'lib/arel_extensions.rb', line 328

def except_predicates(columns)
  attrs = columns.extract! { |node| node.is_a?(Arel::Attribute) }
  non_attrs = columns.extract! { |node| node.is_a?(Arel::Predications) }

  predicates.reject do |node|
    if !non_attrs.empty? && node.equality? && node.left.is_a?(Arel::Predications)
      non_attrs.include?(node.left)
    end || Arel.fetch_attribute(node) do |attr|
      attrs.find { |v| v.eql? attr } || columns.include?(attr.name.to_s) # 👈 replces
      # attrs.include?(attr) || columns.include?(attr.name.to_s)         # 👈 this
      #
      # And that's because our attributes override `==`, so `attrs.include?(attr)` always
      # passes because it returns an equality node.
    end
  end
end