Suppose I have two tables, Email
and VStatus
('V' stands for 'Verification').
class Email(SQLModel, table=True):
id: Optional[int] = Field(default=None, primary_key=True)
email: str
vstatus_id: Optional[int] = Field(default=None, foreign_key='VStatus.id')
vstatus: Optional["VStatus"] = Relationship()
class VStatus(SQLModel, table=True):
id: Optional[int] = Field(default=None, primary_key=True)
vstatus: StatusEnum = Field(default=StatusEnum.Unverified) # InProgress, Verified, Unverified
vdesc: str = Field(default="") # Verification Description
How should I structure my SQLModel tables such that whenever I create a new email via the API say '/create_email', with just a single field email
, it will automatically created a new row in the VStatus
table via the Relationship
defined in the Email
table?
Example:
POST /create_email
{
'email': 'example@example.com'
}
I will get a response that looks like:
response = {
'email': 'example@example.com',
'vstatus_id': '1001', # example
}
And in the VStatus
table, there will be a new row that looks like:
id | vstatus | vdesc |
---|---|---|
1001 | Unverified | Null |