在has_many:through中使用:uniq => true时,Rails 4引入了弃用警告。例如:
has_many :donors, :through => :donations, :uniq => true
产生以下警告:
DEPRECATION WARNING: The following options in your Goal.has_many :donors declaration are deprecated: :uniq. Please use a scope block instead. For example, the following:
has_many :spam_comments, conditions: { spam: true }, class_name: 'Comment'
should be rewritten as the following:
has_many :spam_comments, -> { where spam: true }, class_name: 'Comment'
重写上面的has_many声明的正确方法是什么?