First Check
Commit to Help
Example Code
class Contact(SQLModel, table=True):
"""An entry in the address book."""
id: Optional[int] = Field(default=None, primary_key=True)
first_name: Optional[str]
last_name: Optional[str]
company: Optional[str]
email: Optional[str]
address_id: Optional[int] = Field(default=None, foreign_key="address.id")
address: Optional[Address] = Relationship(
back_populates="contacts", sa_relationship_kwargs={"lazy": "subquery"}
)
invoicing_contact_of: List["Client"] = Relationship(
back_populates="invoicing_contact", sa_relationship_kwargs={"lazy": "subquery"}
)
class Client(SQLModel, table=True):
"""A client the freelancer has contracted with."""
id: Optional[int] = Field(default=None, primary_key=True)
name: str = Field(default="")
# Client 1:1 invoicing Contact
invoicing_contact_id: int = Field(default=None, foreign_key="contact.id")
invoicing_contact: Contact = Relationship(
back_populates="invoicing_contact_of",
sa_relationship_kwargs={"lazy": "subquery"},
)
contracts: List["Contract"] = Relationship(
back_populates="client", sa_relationship_kwargs={"lazy": "subquery"}
)
Description
(As far as I know the documentation does not handle data integrity topics - please point me to the chapter if I am wrong.)
Consider these two model classes Contact and Client. To keep the integrity of the data model, I need the following behavior:
An exception is raised if there is an attempt to delete a Contact that is still the invoicing contact of an existing Client.
Does SQLModel support this, perhaps via SQLAlchemy?
Operating System
macOS
Operating System Details
No response
SQLModel Version
0.0.8
Python Version
3.10
Additional Context
No response
First Check
Commit to Help
Example Code
Description
(As far as I know the documentation does not handle data integrity topics - please point me to the chapter if I am wrong.)
Consider these two model classes
ContactandClient. To keep the integrity of the data model, I need the following behavior:An exception is raised if there is an attempt to delete a
Contactthat is still the invoicing contact of an existingClient.Does SQLModel support this, perhaps via SQLAlchemy?
Operating System
macOS
Operating System Details
No response
SQLModel Version
0.0.8
Python Version
3.10
Additional Context
No response