Skip to content
Discussion options

You must be logged in to vote

I've encountered the same issue and after reading this SQLAlchemy guide I've managed to work around it.

Based to the guide your code should look like this:

class UpsertByModelMixin(SQLModel):
    created_by_id : Optional[int] = Field(default=None, foreign_key="users.id")
    created_by: Optional["User"] = Relationship(sa_relationship_kwargs={ 'foreign_keys': '[UpsertByModelMixin.created_by_id]' })
    
    updated_by_id : Optional[int] = Field(default=None, foreign_key="users.id")
    updated_by: Optional["User"] = Relationship(sa_relationship_kwargs={ 'foreign_keys': '[UpsertByModelMixin.updated_by_id]' })

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by YuriiMotov
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
3 participants
Converted from issue

This discussion was converted from issue #107 on August 13, 2025 11:14.