【问题标题】:How to make where condition include nil value如何使条件包含零值
【发布时间】:2015-03-02 04:15:11
【问题描述】:

我发现 ActiveRecord,漏斗值不是“输入”值

我使 条件

这是我的代码

@calls = Call.searchable.where.not(funnel: "input") 

这些命令运行良好,但结果也是除了 nil 值

我只想漏斗不是'输入'

如何在where语句中添加OR条件

SQL 语句是

select * from call where is_visible = 1 and (funnel != 'input or funnel is null)

【问题讨论】:

    标签: ruby-on-rails ruby ruby-on-rails-4


    【解决方案1】:

    打击代码应该可以帮助你。

    @calls = Call.searchable.where("funnel != 'input' or funnel is null")
    

    【讨论】:

    • 如果是纯字符串,不需要参数化查询,可以写成:Call.searchable.where("funnel != 'input' or funnel is null")
    【解决方案2】:

    如果值是动态的,这也将起作用

    Call.searchable.where("funnel != ? OR funnel is ?”,@value1, nil)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-12-18
      • 2012-09-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多