Access sqlalchemy relationship from 2 related tables #7390
-
|
Hi, I'm new at using fastapi...and I want to know if is possible to access a pydantic relationship in a reverse way ?. Like this. SqlAlchemy models: so if I want to create a pydantic schema for t1 class, is there a way of doing that and append the t2 class accesing the relationship name??. Thank you for your help and excuse my english |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
Beta Was this translation helpful? Give feedback.
-
|
Maybe this can be useful: https://github.com/tiangolo/pydantic-sqlalchemy |
Beta Was this translation helpful? Give feedback.
-
|
Thanks for the help @Kludex ! 🙇 ☕ @lvar you would need a Pydantic model for each SQLAlchemy model, alone, without relationships. You could use pydantic-sqlalchemy for that as @Kludex mentions. Then you could probably create subclasses of those Pydantic models adding the relationships that you want to show. |
Beta Was this translation helpful? Give feedback.
-
|
Assuming the original need was handled, this will be automatically closed now. But feel free to add more comments or create new issues or PRs. |
Beta Was this translation helpful? Give feedback.


Thanks for the help @Kludex ! 🙇 ☕
@lvar you would need a Pydantic model for each SQLAlchemy model, alone, without relationships. You could use pydantic-sqlalchemy for that as @Kludex mentions.
Then you could probably create subclasses of those Pydantic models adding the relationships that you want to show.