gpt4 book ai didi

ruby-on-rails - 如何修复DEPRECATION WARNING : Class level methods will no longer inherit scoping from in Rails 6. 1?

转载 作者:行者123 更新时间:2023-12-03 16:07:43 29 4
gpt4 key购买 nike

最近将我的Rails应用程序更新为6.0。当我运行测试时,我从Referral模型的作用域中收到以下弃用警告:

DEPRECATION WARNING: Class level methods will no longer inherit scoping from `with_all_final_state_fulfillments` in Rails 6.1. To continue using the scoped relation, pass it into the block directly. To instead access the full set of models, as Rails 6.1 will, use `Referral.unscoped`. (called from block in <class:Referral> at /Users/home/workspace/APPNAME/app/models/referral.rb:60)

我所讨论的 Referral模型范围是hacky,但是这样写:

  scope :with_all_final_state_fulfillments, lambda {
final_state_ids = Referral.with_fulfillment_in_final_state.pluck(:id).uniq
not_final_state_ids = Referral.where(id: final_state_ids).with_fulfillment_not_in_final_state.pluck(:id).uniq

id_list = final_state_ids - not_final_state_ids
Referral.where(id: id_list)
}

我在互联网上搜索了有关如何解决此问题的建议, including the Rails GitHub PR进行了更改,但是在任何地方都找不到清晰的 English explanation

如何修复Rail 6.1的已弃用范围?

最佳答案

通过将Referral.的内部范围调用更新为self.来使弃用警告消失:

  scope :with_all_final_state_fulfillments, lambda {
final_state_ids = self.with_fulfillment_in_final_state.pluck(:id).uniq
not_final_state_ids = self.where(id: final_state_ids).with_fulfillment_not_in_final_state.pluck(:id).uniq

id_list = final_state_ids - not_final_state_ids
where(id: id_list)
}

关于ruby-on-rails - 如何修复DEPRECATION WARNING : Class level methods will no longer inherit scoping from in Rails 6. 1?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58650970/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com