我必须创建一个范围来创建活跃的工作,但这感觉有点奇怪,老实说它与 PosgresSQL 紧密耦合:
scope :active, -> { where('reviewed_at NOTNULL and paid_at NOTNULL and end_at >= ?', Date.today) }
你会写这个不同吗?谢谢
我必须创建一个范围来创建活跃的工作,但这感觉有点奇怪,老实说它与 PosgresSQL 紧密耦合:
scope :active, -> { where('reviewed_at NOTNULL and paid_at NOTNULL and end_at >= ?', Date.today) }
你会写这个不同吗?谢谢
一个更短更漂亮的版本将是这样的:
scope :active, -> { where.not(reviewed_at: nil, paid_at: nil).where('end_at >= ?', Date.today) }
你可以where.not
在rails 4中使用
scope :active, -> { where.not(reviewed_at: nil).where.not(paid_at: nil).where('end_at >= ?', Date.today) }