I'm writing a scope that should say select all calls where call_status = open and unit_id is not nil. I'm really weak on Ruby and also new to Rails and am having a hard time expressing this right.
Here what I have:
scope :open_calls, where(:call_status => "open", :unit_id != nil).order("id ASC")
Should I be using a different operator to evaluate nil?
As far as I know there is no way to tell ActiveRecord to build a NULL clause with a hash. But you can chain string-style and hash-style where clauses:
scope :open_calls, where(:call_status => "open").where("unit_id IS NOT NULL").order("id ASC")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With