From 3772d7b0235e5126276690610e3023a74963ae6c Mon Sep 17 00:00:00 2001 From: "Waylon S. Walker" Date: Mon, 22 May 2023 08:27:51 -0500 Subject: [PATCH] add pet relationship --- learn_sql_model/models/hero.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/learn_sql_model/models/hero.py b/learn_sql_model/models/hero.py index 5b197cf..734fdeb 100644 --- a/learn_sql_model/models/hero.py +++ b/learn_sql_model/models/hero.py @@ -1,8 +1,9 @@ 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.pet import Pet class Hero(FastModel, table=True): @@ -11,3 +12,6 @@ class Hero(FastModel, table=True): secret_name: str age: 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")