Fix behaviour of parameter objects with an 'id' key #301
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 #143, which was released somewhere between Ziggy versions
0.6.3
and0.6.7
, a new feature was added to detect when a 'model' object was passed to Ziggy as a route parameter, and use itsid
property to fill named params if possible.This allowed us to do the following:
This is super cool, but there was a bug in its implementation that meant that any route parameter object with an
id
key passed to Ziggy had that key stripped out, or was entirely re-parsed into an array of ordered, unnamed parameters instead. Notably, this made it impossible (or at least very error-prone) to intentionally passid
as a query parameter.This PR re-implements that feature a little more carefully—rather than only checking for the presence of an
id
key, we also now check for the absence of a key matching the route parameter name. I also moved this check to a later point in the process of parsing and replacing the parameters, so it now functions more as a fallback if none of the parameters in question are set explicitly (this also avoids issues when there is actually a named route parameter calledid
).Looking again at the route above:
Fixes #192 and fixes #206.