Why using merge method with scopes isn't working anymore on Rails 3.1?

早过忘川 提交于 2019-12-05 01:09:08

The & method doesn't look like it works anymore (too bad, I found the syntax was neat). You can replace it with ActiveRecord::Relation#merge:

class User < ActiveRecord::Base

  scope :published, lambda {
    joins(:posts).group("users.id").merge(Post.published)
  }
end

Edit

And it looks like it won't be back, trying it in rails 3.0.10 gives a deprecation warning:

DEPRECATION WARNING: Using & to merge relations has been deprecated and will be removed in Rails 3.1. Please use the relation's merge method, instead.

Here's the commit deprecating it, in case someone's interested: https://github.com/rails/rails/commit/66003f596452aba927312c4218dfc8d408166d54

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!