Coverage for docs_src/tutorial/code_structure/tutorial002/hero_model.py: 100%

9 statements  

« prev     ^ index     » next       coverage.py v7.17.2, created at 2026-11-16 00:02 +0000

1from typing import TYPE_CHECKING, Optional 1abcdefghijklm

2 

3from sqlmodel import Field, Relationship, SQLModel 1abcdefghijklm

4 

5if TYPE_CHECKING: 1abcdefghijklm

6 from .team_model import Team 

7 

8 

9class Hero(SQLModel, table=True): 1abcdefghijklm

10 id: int | None = Field(default=None, primary_key=True) 1abcdefghijklm

11 name: str = Field(index=True) 1abcdefghijklm

12 secret_name: str 1abcdefghijklm

13 age: int | None = Field(default=None, index=True) 1abcdefghijklm

14 

15 team_id: int | None = Field(default=None, foreign_key="team.id") 1abcdefghijklm

16 team: Optional["Team"] = Relationship(back_populates="heroes") 1abcdefghijklm