Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails scope where does not equal

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?

like image 253
nulltek Avatar asked Jul 04 '12 00:07

nulltek


1 Answers

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")
like image 190
zetetic Avatar answered Nov 06 '22 08:11

zetetic