-3

I have a user table in that department_id is one of the field and i have to check two condition where :department_id=>current_user.id or department_id=> null.

I do not know how to write query for this in rails3.

Dave Newton
  • 158,873
  • 26
  • 254
  • 302
Abhishek
  • 31
  • 8

1 Answers1

1

Here is an example assuming you have a Customer model.

Customer.where("department_id = ? OR department_id IS NULL", current_user.id)

You may also check the guides here:

http://guides.rubyonrails.org/active_record_querying.html#conditions

deepflame
  • 928
  • 1
  • 8
  • 19