Rails升级3.2到4.0:模型弃用警告



在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,但我收到了Deprecation警告,改为使用范围块。如何重写这个has_many语句以在4.0中工作?

我想这就是你需要的:

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

请参阅https://guides.rubyonrails.org/association_basics.html#scopes-for有许多不同的

更新:

如果要覆盖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-对于有许多选择

相关内容

最新更新