Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails - how to find all rows where a certain column value is nil with where()

I want to return an array with all rows in a table called bookings where the column returned_date is empty.

So far I've tried Booking.where("returned_date <> ''"), which chose all the records where returned_date is present, but I want an inverse selection of this.

like image 365
Mihkel Mark Avatar asked Feb 12 '23 16:02

Mihkel Mark


1 Answers

If you mean to get with returned_date column be null:

Booking.where(returned_date: nil)
like image 158
xdazz Avatar answered Feb 15 '23 11:02

xdazz