Skip to content

SQLModel JSON schema missing relationship fields #1438

Closed Answered by YuriiMotov
imrnck asked this question in Questions
Discussion options

You must be logged in to vote

The solution is to create new model (use inheritance to reduce duplication) and use it as response model:

class HeroBase(SQLModel):
    id: int | None = Field(default=None, primary_key=True)
    name: str

class Hero(HeroBase, table=True):
    team_id: int = Field(foreign_key="team.id")
    team: Team = Relationship()

class HeroPublic(HeroBase):
    team: Team

Read more: https://sqlmodel.tiangolo.com/tutorial/fastapi/relationships/#dont-include-all-the-data

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by YuriiMotov
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
2 participants