kali
kali

Reputation: 133

ActiveRecord rails 4 not equal to condition

I am using rails 4 for developing my application. I have a problem in my active record query with not equal to condition. I am not getting required output. I think there is a problem with not equal to part.

@available_rooms = Room.joins("LEFT OUTER JOIN reservations ON reservations.room_id = rooms.id").where("category_id = ? AND arrival_date != ?",params[:category],params[:arrival_date])

Upvotes: 3

Views: 760

Answers (2)

Cyzanfar
Cyzanfar

Reputation: 7136

In some version of SQL not equal is written as !=

Try this using the comparator <> like so:

 @available_rooms = Room.joins("LEFT OUTER JOIN reservations ON reservations.room_id = rooms.id")
.where("category_id = ? AND arrival_date <> ?",params[:category],params[:arrival_date])

Upvotes: 0

potashin
potashin

Reputation: 44581

You can use where.not() in Rails 4 :

 @available_rooms = Room.joins("LEFT OUTER JOIN reservations ON reservations.room_id = rooms.id")
                        .where(category_id: params[:category])
                        .where.not(arrival_date: params[:arrival_date])

Upvotes: 1

Related Questions