1

我必须创建一个范围来创建活跃的工作,但这感觉有点奇怪,老实说它与 PosgresSQL 紧密耦合:

  scope :active, -> { where('reviewed_at NOTNULL and paid_at NOTNULL and end_at >= ?', Date.today) }

你会写这个不同吗?谢谢

4

2 回答 2

2

一个更短更漂亮的版本将是这样的:

scope :active, -> { where.not(reviewed_at: nil, paid_at: nil).where('end_at >= ?', Date.today) }
于 2016-02-28T07:26:05.337 回答
0

你可以where.not在rails 4中使用

scope :active, -> { where.not(reviewed_at: nil).where.not(paid_at: nil).where('end_at >= ?', Date.today) }
于 2016-02-28T07:01:42.903 回答