Repository navigation
Conversation
Collections built by find(:all) only kept the query options in original_params, so calling first_or_create or first_or_initialize on a nested resource built a record without its prefix options. Creating it raised MissingPrefixParam, and an initialized record could not be saved. Both methods also called Hash#update on original_params, so the attributes passed to them leaked into later where calls on the same collection.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
first_or_createandfirst_or_initializedon't work on nested resources. For a resource likethis raises
ActiveResource::MissingPrefixParam: person_id prefix_option is missingwhen nothing matches:and
first_or_initializereturns a record with emptyprefix_options, so it can't be saved.find_everyonly stored the query options in the collection'soriginal_paramsand dropped the prefix options, so the record built fromoriginal_paramsnever gotperson_id. This keeps the prefix options inoriginal_params, so the new record gets them back throughload, the same wayStreetAddress.new(person_id: 1, ...)does.original_paramsfor resources without a prefix stays the same.While there, both methods called
original_params.update(attributes), which changed the collection'soriginal_paramsin place, so the attributes leaked into a laterwhereon the same collection. They now usemerge.