add pet relationship

This commit is contained in:
Waylon Walker 2023-05-22 08:27:51 -05:00
parent 5e824f3bb3
commit 3772d7b023
No known key found for this signature in database
GPG key ID: 66E2BF2B4190EFE4

View file

@ -1,8 +1,9 @@
from typing import Optional from typing import Optional
from sqlmodel import Field from sqlmodel import Field, Relationship
from learn_sql_model.models.fast_model import FastModel from learn_sql_model.models.fast_model import FastModel
from learn_sql_model.models.pet import Pet
class Hero(FastModel, table=True): class Hero(FastModel, table=True):
@ -11,3 +12,6 @@ class Hero(FastModel, table=True):
secret_name: str secret_name: str
age: Optional[int] = None age: Optional[int] = None
shoe_size: Optional[int] = None shoe_size: Optional[int] = None
pet_id: Optional[int] = Field(default=None, foreign_key="pet.id")
pet: Optional[Pet] = Relationship(back_populates="hero")