improvement: warn if manual relationship has missing source_attribute #2560
+198
−8
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.
Reworks the ValidateRelationshipAttributes verifier so that it also warns of missing source attributes for manual relationships instead of ignoring them.
For manual, only do this specific type of verification, Don't do the rest of the verifications since they aren't applicable
Notes
Reason I made this is because I spent longer than I'd like debugging an error when defining a manual relationship on a resource without an :id primary key.
Specifically if you do this and then try to load the relationship you will get an error like this (See the NoSuchAttribute :id error):
This is because source_attribute (:id by default) is selected for manual actions here
It might seem obvious, but it was confusing to me, and I hope that emitting this warning can help save people some time debugging this if they make this mistake.
If you want to reproduce the error yourself you can check out this branch and run the test
it allows loading manual relationships with non :id pkey, regardless of source_attributeviamix test test/actions/load_test.exs:1443Contributor checklist
Leave anything that you believe does not apply unchecked.