1

我正在使用 Rails 4.2.3。我有这两个模型

class Address < ActiveRecord::Base
    …
    has_one :user

class User < ActiveRecord::Base
  belongs_to :address
  default_scope includes(:address) 

我想在加载“MyObject”时自动加载父关联,但在“default_scope”行出现此错误……</p>

Support for calling #default_scope without a block is removed. For example instead of `default_scope where(color: 'red')`, please use `default_scope { where(color: 'red') }`. (Alternatively you can just redefine self.default_scope.)

如何调整我的“default_scope”行以自动加载我的父关联?

4

1 回答 1

2
  • 您的行中缺少块,请像这样更改:

    default_scope { includes(:address) }
    
于 2016-07-25T03:14:49.033 回答