Recently updated my Rails app to 6.0. When I run my tests I get the following deprecation warning from a scope on my Referral
model:
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)
My Referral
model scope in question is hacky, but written like this:
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)
}
I've searched all around the internet for advice on how to fix this deprecation, including the Rails GitHub PR's making the change, but haven't found a clear English explanation anywhere.
How do I fix this deprecated scope for Rail 6.1?
Made the deprecation warning go away by updating inside scope calls of Referral.
to 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)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With