【发布时间】:2013-05-10 07:36:17
【问题描述】:
Rails 4 在使用 :uniq => true 和 has_many :through 时引入了弃用警告。例如:
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 声明的正确方法是什么?
【问题讨论】:
标签: ruby-on-rails activerecord rails-activerecord ruby-on-rails-4