2013-04-25 39 views
2

我的理解是可以做到如何使用「在哪裏」,「有」和「或」

scope :public_visible, where("(status = ?) OR (end_date > ?)", :published, Date.today) 

但我想要做的是以下兩個作用域與OR

結合什麼範圍
scope :succeeded, having("SUM(orders.sum) >= goal") 
scope :ongoing, where("end_date >= ?", Date.today) 

這可能嗎?無論是以sql還是主動記錄的方式。

謝謝大家。

回答

1

不是一個完美的解決方案,但最後我做

scope :succeeded_or_ongoing, where("id in (?) or id in (?)", Project.succeeded.map(&:id), Project.ongoing.map(&:id)) 
0

這是更好地在我的真實想法使用阿雷爾(link)。你會碰到這樣的:

def succeeded_or_ongoing 
    where("id in (?) or id in (?)", Project.succeeded.map(&:id), Project.ongoing.map(&:id)) 
end 

然後做Project.succeeded_or_ongoing

相關問題