Q:

Omit chaining parenthesis when using multiple Arel OR clauses

I'm attempting to abstract out a body of raw sql someone shoved in our codebase, and we're using Rails 4.2.8. I want to generate sql that ends with a where clause like so:
WHERE col1=1 OR col2=1 OR col3=1

I'm using the following Arel in an attempt to generate that sql:
my_clause = mytable[:col1].eq(1)
    .or(mytable[:col2].eq(1))
    .or(mytable[:col3].eq(1))
puts my_clause.to_sql

What I actually get is:
WHERE (col1=1 OR col2=1) OR col3=1

I realize that my code doesn't generate the word 'WHERE'. I added that in for the sake of clarity.
Our dba has been able to assure me that it's not a big deal in terms of performance, but it's triggering my OCD and I want to know what Arel syntax would I use to get the chained OR clauses w/o parens.  

A:

You could try to build the query you want with Arel::Nodes::Or directly (instead of or method that takes care of the parenthesis):
[
  mytable[:col1].eq(1), 
  mytable[:col2].eq(1), 
  mytable[:col3].eq(1)
].reduce {|clause, condition| 
  Arel::Nodes::Or.new(clause, condition) 
}

