ruby on rails 3.2 - Cannot programmatically combine AND and OR conditions using Arel -
given sql conditions cond1, cond2 , cond3 generated using arel operators (.eq example), cannot seem use arel produce sql:
select * <table> (cond1 , cond2) or cond3 this because , conditions use .where(), can't .or() result of .where(). can .or() conditions inside .where(). i.e. .where , .or not on same "level", guess 1 needs dedicated .and() method on same level .or().
note brackets around (cond1 , cond2) denotes these conditions anded @ same time, or cond3 added in iteration of loop. make no difference result of query.
i've read arel readme , there no example situation , can't figure out how dynamically build query (in loop) using squeel, has or operator |.
arel::nodes::grouping wraps nodes in parentheses.
arel::nodes::grouping.new(arel::nodes::and.new("blah", "there")).to_sql # => ('blah' , 'there')
Comments
Post a Comment