Rails范围为null还是空?

时间:2013-01-30 14:09:32

标签: ruby-on-rails ruby-on-rails-3 scope rails-activerecord

我希望范围cancelled_at为空或空/空白的所有记录。

我发现很多帖子都要求IS NOT NULL /空/空白......但我需要相反。

我确信这很简单,但我很难过。

这是我目前得到的:

scope :active, where("cancelled_at IS NULL")

1 个答案:

答案 0 :(得分:3)

你试过吗?

 Patient.where("created_at IS NULL or CAST(created_at as text) = ''")
 # SELECT "patients".* FROM "patients" WHERE (created_at IS NULL or CAST(created_at as text) = '')