Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compare null in rails active record query

How can I match null in rails active record.

User.where(['id = ? and active = ? and activation_code = ?', params[:id], 0, NULL]).first

or

 User.where(['id = ? and active = ? and activation_code = ?', params[:id], 0, nil]).first

Both are not working.

like image 949
Mohit Jain Avatar asked Dec 02 '10 22:12

Mohit Jain


1 Answers

In Rails 4 you can do this:

User.where(id: params[:id], active: 0).where.not(activation_code: nil)
like image 144
Lucas Moulin Avatar answered Oct 04 '22 09:10

Lucas Moulin