SORU
15 Mayıs 2013, ÇARŞAMBA


Kullanarak has_many :üzerinden zaman admin uyarı :özgün olarak Raylar 4

Kullanırken admin bir uyarı tanıttı: = ^ hizmetlerinde . raylar 4 has_many :gerçek. Örneğin:

has_many :donors, :through => :donations, :uniq => true

Verimleri aşağıdaki uyarı:

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'

Yukarıda has_many bildirimi yeniden yazmak için doğru yolu nedir?

CEVAP
22 Mayıs 2013, ÇARŞAMBA


uniq seçeneği kapsamında bir blok içine taşınması gerekir. Not bu kapsam engellemek gerekiyor. ikinci parametre için has_many (yani bırakamazsın sonunda hattı, ihtiyaçları için taşınmadan önce :through => :donations):

has_many :donors, -> { uniq }, :through => :donations

Garip görünebilir, ama eğer birden fazla parametre olması durumunda göz önüne alırsak biraz daha mantıklı. Örneğin, bu:

has_many :donors, :through => :donations, :uniq => true, :order => "name", :conditions => "age < 30"

olur:

has_many :donors, -> { where("age < 30").order("name").uniq }, :through => :donations

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • alexis gillis

    alexis gilli

    23 HAZİRAN 2011
  • atKristaBradford

    atKristaBrad

    4 Aralık 2010
  • SuppressedStorm

    SuppressedSt

    11 AĞUSTOS 2013