First Check
Commit to Help
Example Code
class User(SQLModel):
__tablename__ = "users"
id: Optional[str]
cars: List[Car] = Relationship(sa_relationship=RelationshipProperty("Car", back_populates="user")
class Car(SQLModel):
...
user_id: str = Field(default=None, foreign_key="users.id")
user: User = Relationship(sa_relationship=RelationshipProperty("User", back_populates="cars"))
is_main_car: bool
Description
I have two tables that have a many to one relationship, such as the one described above. Any given user can only have a single car that is_main_car. Additionally, the first car a user gets must be the main car.
I am trying to determine how the transactional semantics work with this relationship within a Session. If I read the user, and then use the user.cars field to determine if the user has 0 cars or already has a main car, can I rely on that condition still being true when I write my new main Car row to the Cars table (assuming it is all within a single Session)?
Operating System
macOS
Operating System Details
No response
SQLModel Version
0.0.4
Python Version
3.9.7
Additional Context
No response
First Check
Commit to Help
Example Code
Description
I have two tables that have a many to one relationship, such as the one described above. Any given user can only have a single car that
is_main_car. Additionally, the first car a user gets must be the main car.I am trying to determine how the transactional semantics work with this relationship within a Session. If I read the
user, and then use theuser.carsfield to determine if the user has 0 cars or already has a main car, can I rely on that condition still being true when I write my new mainCarrow to theCarstable (assuming it is all within a single Session)?Operating System
macOS
Operating System Details
No response
SQLModel Version
0.0.4
Python Version
3.9.7
Additional Context
No response