def flatten_to_sql(*values)
      flatten_safely(values) do |value|
        value = yield value if block_given?
        to_arel_sql(value)
      end
    end
def flatten_to_sql(*values)
      flatten_safely(values) do |value|
        value = yield value if block_given?
        to_arel_sql(value)
      end
    end
We need to ensure we can flatten nested ActiveRecord::Relations
 that might have been nested due to the (splat)*args parameters

 Note: calling `Array.flatten[!]/1` will actually remove all AR relations from the array.