Rails 3.1 中的范围关联
我们过去在 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 中似乎不再起作用了,你知道是否有新的方法可以做到这一点? 谢谢
Something very convenient we used to use in rails 3.0 is the scope reusability. Lets see an example.
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
But it does not seems to work anymore in 3.1, do you know if there is a new way to do that ?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我对此的反馈是,它确实有效,但不确定我的问题来自哪里。
您还可以使用 merge() 函数,&是一条捷径。
干杯
My feedback on this, it does work, not sure where my problem was coming from.
You can also use the merge() function, & is a shortcut.
Cheers