2016-02-28 67 views
1

我必須創建一個範圍,以創建活動的作業,但這種感覺有點奇怪,誠實它的緊耦合PosgresSQL:軌道4範圍NOTNULL重構

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

你會寫這種不同?謝謝

回答

2

使用where.not較短&更漂亮的版本將是這樣的:

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

您可以在軌道4,5

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