Skip to content
Discussion options

You must be logged in to vote

Leaving this for anyone searching for the same issue in the future!
Here is my way of doing it. It looks sort if the same as @jdwil solution above (which i have not tested) but you don't need to use SQLAlchemy stuff directly.

class MyFirstModel(SQLModel, table=True):
    id: int | None = Field(default=None, primary_key=True)

    first: Optional["MySecondModel"] = Relationship(
        back_populates="left",
        sa_relationship_kwargs={"foreign_keys": "MySecondModel.left_id"}
    )
    second: Optional["MySecondModel"] = Relationship(
        back_populates="right",
        sa_relationship_kwargs={"foreign_keys": "MySecondModel.right_id"}
    )

class MySecondModel(SQLModel, table=True)…

Replies: 4 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@PrinceDobariya0710
Comment options

Answer selected by YuriiMotov
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
6 participants