Skip to content
Discussion options

You must be logged in to vote

I think the most straightforward solution here would be to mimic structure of DB models in Read models: create the CompanyUserRead schema with the rank field and add it to UserRead schema.

class UserBase(SQLModel):
    username: str

class CompanyUserRead(SQLModel):
    rank: str

class UserRead(UserBase):
    company: CompanyUserRead

And then add a computed field to provide direct access to the rank field:

class UserRead(UserBase):
    company: CompanyUserRead

    @computed_field
    @property
    def rank(self) -> str:
        return self.company.rank

You can also exclude company field from output schema:

    company: CompanyUserRead = Field(exclude=True)

Runnable code example in the d…

Replies: 14 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

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

This discussion was converted from issue #77 on May 18, 2026 13:56.