I am writing a scope that should say select all calls where call_status = open and unit_id is not zero. I'm very weak at Ruby, and also new to Rails, and it's hard for me to express this right.
Here is what I have:
scope :open_calls, where(:call_status => "open", :unit_id != nil).order("id ASC")
Should I use another operator to compute nil?
As far as I know, there is no way to tell ActiveRecord about creating a NULL clause with a hash. But you can link the string style and the hash style, where cluses:
scope :open_calls, where(:call_status => "open").where("unit_id IS NOT NULL").order("id ASC")
You can do it:
scope :open_calls, where("call_status IS ? AND unit_id IS NOT ?", "open", nil).order("id ASC")
, "open" nil , ? . SQL- - / .. . . .
"open"
nil
?