ActiveRecord 4 rails not equal to condition

I am using rails 4 to develop my application. I have a problem with my active record request not equal to a condition. I am not getting the desired result. I think there is a problem with not equal parts.

@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])

      

+3


source to share


2 answers


Some version of SQL does not equalize as !=

Try using a comparator <>

like this:



 @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])

      

0


source


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])

      

+1


source







All Articles