当使用 :uniq => true 和 has_many :through 时,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 声明的正确方法是什么?