Skip to content

Unable to get a nested (join) response on 1:1 relationship #1485

Discussion options

You must be logged in to vote

Relationship properties are not serialized to prevent loops.
The solution is explained in Multiple Models with FastAPI.
You need to create one more model:

class AdvancedProjectOutput(SQLModel):
    PROJECT: str
    MASTERDESIGN_MODEL: Optional[Design]

And use it for result validation and serialization:

        proj_db = session.get(AdvancedProject, "project")
        proj_output = AdvancedProjectOutput.model_validate(
            proj_db, from_attributes=True
        )
        print(proj_output.model_dump())

Output:

{
    "PROJECT": "project",
    "MASTERDESIGN_MODEL": {"DESIGN": "design"},
}

Runnable code example in details:

from typing import Optional

from sqlmodel import Field, Relat…

Replies: 4 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
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
3 participants
Converted from issue

This discussion was converted from issue #284 on August 11, 2025 21:00.