Skip to content
Discussion options

You must be logged in to vote

I'm fairly new to this, but I seem to have managed to get it to work with

class User(SQLModel, table=True):
    id: int = Field(default=None, primary_key=True)
    parents: List["User"] = Relationship(
        back_populates="children",
        link_model=UserLink,
        sa_relationship_kwargs=dict(
            primaryjoin="User.id==UserLink.child_id",
            secondaryjoin="User.id==UserLink.parent_id",
        ),
    )
    children: List["User"] = Relationship(
        back_populates="parents",
        link_model=UserLink,
        sa_relationship_kwargs=dict(
            primaryjoin="User.id==UserLink.parent_id",
            secondaryjoin="User.id==UserLink.child_id",
        ),
 …

Replies: 6 comments

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
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
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
3 participants
Converted from issue

This discussion was converted from issue #89 on August 14, 2025 15:35.