How to display many to many relationships in swagger after using type_checking #1443
Answered
by
YuriiMotov
lionjiadong
asked this question in
Questions
-
First Check
Commit to Help
Example Codefrom fastapi import APIRouter, Query, Request
from sqlmodel import select
from src.database.core import SessionDep
from src.test.models.team import TeamOut, Team, TeamBase
team_router = APIRouter(
prefix="/team",
tags=["team"],
)
@team_router.get("/", response_model=list[TeamOut])
async def read_teams(
request: Request,
session: SessionDep,
offset: int = 0,
limit: int = Query(default=100, le=100),
):
teams = (await session.exec(select(Team).offset(offset).limit(limit))).all()
return teams DescriptionThis is my directory structure
When I run and access http://127.0.0.1:8000/docs# , I got this: console got this:
How to implement nested response_model after applying the official loop pouring solution Operating SystemmacOS Operating System DetailsNo response SQLModel Version0.0.24 Python VersionPython 3.13.5 Additional ContextNo response |
Beta Was this translation helpful? Give feedback.
Answered by
YuriiMotov
Aug 21, 2025
Replies: 1 comment 1 reply
-
You need to rebuild models. from .hero import Hero, HeroBase, HeroOut # noqa: F401
from .team import Team, TeamBase, TeamOut # noqa: F401
HeroOut.model_rebuild()
TeamOut.model_rebuild() |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
YuriiMotov
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You need to rebuild models.
Simple way is to add the following to
models/__init__.py
: