Here's an example (which doesn't make sense, but good as an example)
t = DimensionType.arel_table
q = t.where(
t[:label].eq('a').and(t[:label].eq('b'))
.or(t[:label].eq('c').and(t[:label].eq('d')))
.or(t[:label].eq('e').and(t[:label].eq('f')))
.or(t[:label].eq('g').and(t[:label].eq('e')))
).to_sql
puts q
Here's the output:
SELECT FROM "dimension_types" WHERE ((("dimension_types"."label" = 'a' AND "dimension_types"."label" = 'b' OR "dimension_types"."label" = 'c' AND "dimension_types"."label" = 'd') OR "dimension_types"."label" = 'e' AND "dimension_types"."label" = 'f') OR "dimension_types"."label" = 'g' AND "dimension_types"."label" = 'e')
What purpose do the parentheses serve? If none, how to avoid having them? They put the where part in a kind of hierarchical structure which might possibly impact query optimization.
EDIT: the intent is to have a query like this (in a contrived meta language):
(a and b) or (b and c) or (d and e)
which is the same without parentheses because and
takes precedence over or
a and b or b and c or d and e
Correct me pls if I'm wrong.