Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Conversation

foxlance
Copy link
Contributor

This fix addresses the NoMethodError: undefined method _deprecated_scope_block for ActiveRecord::AssociationRelation error one might encounter when using .first_or_create, and possibly .first_or_initialize after a where clause on an association, e.g.

Facility.first.amenities.where(name: 'pool').first_or_create
NoMethodError: undefined method `_deprecated_scope_block' for #<ActiveRecord::AssociationRelation []>

This bug is specific to Rails 6.1.x with protected_attributes_continued v1.7.0. Downgrading to protected_attributes_continued v1.6.0 works if one is not after any specific 1.7.0 features.

This fix is inspired by rails/rails@255a7ef.

Copy link
Owner

@westonganger westonganger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this. I have left some comments.

CHANGELOG.md Outdated Show resolved Hide resolved
lib/protected_attributes/version.rb Outdated Show resolved Hide resolved
@foxlance foxlance force-pushed the fix/remove_deprecated_scope_block_on_association_relation branch from 2024afd to 73bcc12 Compare January 28, 2021 10:13
@foxlance foxlance force-pushed the fix/remove_deprecated_scope_block_on_association_relation branch from 73bcc12 to 1efbf6f Compare January 28, 2021 10:16
@westonganger
Copy link
Owner

westonganger commented Jan 28, 2021

PR that makes the original change in behaviour - rails/rails#29301 was merged on June 28, 2017. Was merged before Rails 5.1.3 but I think was only released for 5.2.0 (rails/rails#33387).

PR which removes the scoping block - rails/rails#33394 was merged on July 19, 2018. Would be included in Rails 5.2.1

I think that lets keep the scoping block for versions 5.1 and below. Can you add this change?

@foxlance
Copy link
Contributor Author

@westonganger Done! Let me know if you find anything else worth addressing.

@westonganger
Copy link
Owner

westonganger commented Jan 29, 2021

@foxlance you added the scoping back for all Rails versions. We want the scoping block to be removed for Rails 5.2+.

@foxlance
Copy link
Contributor Author

foxlance commented Feb 1, 2021

@westonganger Is the recent commit what you have in mind?

@westonganger
Copy link
Owner

Merged. Thanks for your contribution.

@westonganger westonganger merged commit ec248bd into westonganger:master Feb 2, 2021
@westonganger
Copy link
Owner

v1.8.0 is now released which contains this fix.

avit added a commit to avit/protected_attributes_continued that referenced this pull request Mar 24, 2021
Fixes a regression from westonganger#21 where the scoping block was removed.
avit added a commit to avit/protected_attributes_continued that referenced this pull request Mar 24, 2021
Fixes a regression from westonganger#21 where the scoping block was removed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants