簡體   English   中英

Rails升級3.2到4.0:模型棄用警告

[英]Rails Upgrade 3.2 to 4.0: Model deprecation warning

在Rails 3.2中,我的用戶模型如下->

User model

has_many :billing_invoices, :through => :user_purchases, :select => "DISTINCT billing_invoices.invoice_date,billing_invoices.account_number"

我試圖升級到Rails 4.0,但我收到了棄用警告,改為使用范圍塊。 如何重寫此has_many語句以在4.0中工作?

我認為這是您需要的:

has_many :billing_invoices, -> { distinct }, through: :user_purchases

參見https://guides.rubyonrails.org/association_basics.html#scopes-for-has-many-distinct

更新:

如果要覆蓋SELECT則:

has_many :billing_invoices, -> { select("DISTINCT billing_invoices.invoice_date,billing_invoices.account_number") }, :through => :user_purchases

請參閱: https//guides.rubyonrails.org/association_basics.html#scopes-for-has-many-select

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM