nul*_*tek 5 activerecord ruby-on-rails-3
我正在编写一个范围,应该说选择call_status = open且unit_id不是nil的所有调用.我对Ruby非常弱,也是Rails的新手,我很难表达这一点.
在这里我有:
scope :open_calls, where(:call_status => "open", :unit_id != nil).order("id ASC")
Run Code Online (Sandbox Code Playgroud)
我应该使用不同的运算符来评估nil吗?
据我所知,没有办法告诉ActiveRecord使用哈希构建一个NULL子句.但你可以链接字符串样式和哈希样式where子句:
scope :open_calls, where(:call_status => "open").where("unit_id IS NOT NULL").order("id ASC")
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9389 次 |
| 最近记录: |