-
-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add fk_as_int option to get_pydantic() #893
Open
iron3oxide
wants to merge
8
commits into
collerek:master
Choose a base branch
from
iron3oxide:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains 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
…nt in the resulting pydantic model This can be useful when using get_pydantic() to create read or create models, as one probably doesn't want to have to specify the whole related model in a request in order to pass validation, see collerek#343.
More specific testing would have required new models, which I frankly was too lazy to implement. Also fixed a typo in the file name.
This way "fk_as_int={"item__category"} should generate a nested item model in which the related category is not a nested model but an ID/PositiveInt. I tried to allow for infinite nesting in fk_as_int but didn't manage to implement it, in fact idk if it's even possible to do with the current relation algorithm.
This way there are two separate recursion paths, which might be the better solution.
Caveat: No M2M tests yet
Might also be useful in the fastapi parts of the documentation, but the methods section is prominently linked there.
Codecov Report
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## master #893 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 201 201
Lines 16647 16680 +33
=========================================
+ Hits 16647 16680 +33
|
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.
This allows to create pydantic models that contain the FK ID instead of the full related model for each field specified in
fk_as_int
. To see why this can be useful, check #343.Unfortunately I didn't manage to allow for more than one level of nesting in the given dict/set, meaning one can only skip the conversion of a directly related model, not an indirectly related one. A more concrete example of this caveat has been added to the docs.