Module | Sequel::Dataset::SplitArrayNil |
In: |
lib/sequel/extensions/split_array_nil.rb
|
Over the IN/NOT IN handling with an array of values where one of the values in the array is nil, by removing nils from the array of values, and using a separate OR IS NULL clause for IN or AND IS NOT NULL clause for NOT IN.
# File lib/sequel/extensions/split_array_nil.rb, line 46 46: def complex_expression_sql_append(sql, op, args) 47: case op 48: when :IN, "NOT IN""NOT IN" 49: vals = args.at(1) 50: if vals.is_a?(Array) && vals.any?(&:nil?) 51: cols = args.at(0) 52: vals = vals.compact 53: c = Sequel::SQL::BooleanExpression 54: if op == :IN 55: literal_append(sql, c.new(:OR, c.new(:IN, cols, vals), c.new(:IS, cols, nil))) 56: else 57: literal_append(sql, c.new(:AND, c.new("NOT IN""NOT IN", cols, vals), c.new("IS NOT""IS NOT", cols, nil))) 58: end 59: else 60: super 61: end 62: else 63: super 64: end 65: end