mirror of
				https://github.com/fastapi/sqlmodel.git
				synced 2025-11-04 14:47:08 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			22 lines
		
	
	
		
			652 B
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			22 lines
		
	
	
		
			652 B
		
	
	
	
		
			Python
		
	
	
	
	
	
from typing import List, Optional
 | 
						|
 | 
						|
from sqlmodel import Field, Relationship, SQLModel
 | 
						|
 | 
						|
 | 
						|
class Team(SQLModel, table=True):
 | 
						|
    id: Optional[int] = Field(default=None, primary_key=True)
 | 
						|
    name: str = Field(index=True)
 | 
						|
    headquarters: str
 | 
						|
 | 
						|
    heroes: List["Hero"] = Relationship(back_populates="team")
 | 
						|
 | 
						|
 | 
						|
class Hero(SQLModel, table=True):
 | 
						|
    id: Optional[int] = Field(default=None, primary_key=True)
 | 
						|
    name: str = Field(index=True)
 | 
						|
    secret_name: str
 | 
						|
    age: Optional[int] = Field(default=None, index=True)
 | 
						|
 | 
						|
    team_id: Optional[int] = Field(default=None, foreign_key="team.id")
 | 
						|
    team: Optional[Team] = Relationship(back_populates="heroes")
 |