使用has_many声明和:uniq在Rails 4中没有其他参数的弃用警告

时间:2018-08-13 13:20:14

标签: ruby-on-rails ruby-on-rails-4 scope deprecation-warning

所以我发现了

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'

但是我有很多行代码,其中uniq是唯一的参数,例如: has_and_belongs_to_many :accounts, uniq: true

我如何将其写成一个块?我已经尝试过has_and_belongs_to_many :accounts, -> { uniq },但是我读到在代码行的末尾不能这样写uniq

0 个答案:

没有答案