我正在使用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”行上收到此错误...
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”行以自动加载我的父关联?
答案 0 :(得分:0)
您的线路中缺少阻止,请按以下方式更改:
default_scope { includes(:address) }