The uniq
option needs to be moved into a scope block. Note that the scope block needs to be the second parameter to has_many
(i.e. you can't leave it at the end of the line, it needs to be moved before the :through => :donations
part):
has_many :donors, -> { uniq }, :through => :donations
It may look odd, but it makes a little more sense if you consider the case where you have multiple parameters. For example, this:
has_many :donors, :through => :donations, :uniq => true, :order => "name", :conditions => "age < 30"
becomes:
has_many :donors, -> { where("age < 30").order("name").uniq }, :through => :donations
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…