Rails - 如何使用 where() 查找某个列值为 nil 的所有行 [英] Rails - how to find all rows where a certain column value is nil with where()
本文介绍了Rails - 如何使用 where() 查找某个列值为 nil 的所有行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想返回一个包含名为 bookings
的表中所有行的数组,其中 returned_date
列为空.
I want to return an array with all rows in a table called bookings
where the column returned_date
is empty.
到目前为止,我已经尝试过 Booking.where("returned_date <> ''")
,它选择了存在返回日期的所有记录,但我想要一个相反的选择.
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.
推荐答案
如果你的意思是让 returned_date
列成为 null
:
If you mean to get with returned_date
column be null
:
Booking.where(returned_date: nil)
这篇关于Rails - 如何使用 where() 查找某个列值为 nil 的所有行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文