0

我们过去在 rails 3.0 中使用的非常方便的东西是范围的可重用性。让我们看一个例子。

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 中不再起作用,你知道是否有新的方法可以做到这一点吗?谢谢

4

1 回答 1

1

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

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

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

干杯

于 2012-04-24T05:05:40.657 回答