Search code examples
rubysequel

Ordering of Sequel (gem) subqueries


I am looking for a way to concatenate subqueries with a specific ordering.

The following query:

User.where(a: 3).where(#<Sequel::SQL::BooleanExpression @op=>:"NOT IN", @args=>[:b, [0.25, 0.31, 0.78]]>).or(b: nil)

groups like so:

(((a == 3) AND (b != [...]))
OR (b == nil))

However what I am trying to achieve is

((a == 3) 
AND ((b != [...]) OR (b == nil))

Any ideas how one can achieve this?


Solution

  • You probably want something like:

    User.where(:a=>3).where(Sequel.~(:b=>[0.25, 0.31, 0.78]) | {:b=>nil})