Class: ActiveRecord::Relation::WhereClause

Inherits:
Object
  • Object
show all
Defined in:
lib/composite_primary_keys/relation/where_clause.rb

Instance Method Summary collapse

Instance Method Details

#to_h(table_name = nil, equality_only: false) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/composite_primary_keys/relation/where_clause.rb', line 4

def to_h(table_name = nil, equality_only: false)
  equalities = equalities(predicates, equality_only)

  # CPK Adds this line, because ours are coming in with AND->{EQUALITY, EQUALITY}
  equalities = predicates.grep(Arel::Nodes::And).map(&:children).flatten.grep(Arel::Nodes::Equality) if equalities.empty?

  equalities.each_with_object({}) do |node, hash|
    next if table_name&.!= node.left.relation.name
    name = node.left.name.to_s
    value = extract_node_value(node.right)
    hash[name] = value
  end
end