如何修复弃用警告:Class 级别的方法将不再从 Rails 6.1 中继承作用域?
How to fix DEPRECATION WARNING: Class level methods will no longer inherit scoping from in Rails 6.1?
最近将我的 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
模型范围有问题,但是这样写的:
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's making the change, but haven't found a clear 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)
}
最近将我的 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
模型范围有问题,但是这样写的:
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's making the change, but haven't found a clear 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)
}