fix(associations): redefine build_record for CollectionAssociation #26
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In Rails 6.0.4, CollectionAssociation defines its own implementation of build_record which overrides the one inherited from the Association base class. This breaks protected_attributes_continued's redefinition because now CollectionAssociation is no longer using the implementation from the super class.
I fixed this by checking if CollectionAssociation defines its own build_record by using private_instance_methods(false). If it does, I undef'd it, and then added a new implementation that accepts the extra options argument. The implementation is just the same as the one from main.
See this commit for the addition of build_record to CollectionAssociation: rails/rails@1192867
Only appears in the 6-0-stable branch, first released in the v6.0.4 tag.
Does not appear in the 6-1-stable or main branches. I assume the issue this was fixing is not present in those branches, but I'm not sure. However, in 6.1.x,
private_instance_methods(false).include?(:build_record)
returns false, so I think the conditional I used to target this patch should only hit 6.0.4.