0

我们在rails 3.0中使用的一些非常方便的范围是可重用性。让我们看一个例子。rails 3.1中的范围关联

class Wheel < AR::B 
    belongs_to :car 
    scope :deflated, where (:deflated => true) 
end 

class Car < AR::B 
    has_many :wheels 
    scope :out_of_service, joins(:wheels) & Wheel.deflated 
end 

但它似乎没有在3.1中工作,你知道是否有一种新的方式来做到这一点? 谢谢

回答

1

我对此的反馈,它确实有效,不知道我的问题来自哪里。

你也可以使用merge()函数,&是一个快捷方式。

scope :out_of_service, joins(:wheels).merge(Wheel.deflated) 

干杯