Add fk_as_int option to get_pydantic() by iron3oxide · Pull Request #893 · ormar-orm/ormar

and others added 7 commits

October 23, 2022 02:08
…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 ormar-orm#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.
Might also be useful in the fastapi parts of the documentation, but the methods section is prominently linked there.

@collerek