Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Query for records where a column is not nil in Rails 4

In code:

<% @hotelUser=HotelUser.find( cookies[:user_id2]) %>

<%= debug @orderLast=Order.where(:email=>@hotelUser.email,"order.hotel_user_id IS NOT NULL").last%>

I am getting syntax error after executing this code.I want to search hotel_user_id where hotel_user_id != nil or empty?. Please tell me the right syntax.

like image 529
Uday kumar das Avatar asked Jan 06 '15 12:01

Uday kumar das


1 Answers

Order.where(email: @hotelUser.email).where.not(hotel_user_id: nil)
like image 110
Jiří Pospíšil Avatar answered Oct 05 '22 10:10

Jiří Pospíšil