Skip to content
Discussion options

You must be logged in to vote

You should import Relationship from sqlmodel, not from sqlalchemy.

And then pass uselist via sa_relationship_kwargs:

from sqlmodel import Relationship
...

    habitue: Optional["Habitue"] = Relationship(back_populates="user", sa_relationship_kwargs={"uselist": False})
    streamer: Optional["Streamer"] = Relationship(back_populates="user", sa_relationship_kwargs={"uselist": False})

Runnable code example in the details:

from typing import Optional

from pydantic import BaseModel
from sqlmodel import (
    AutoString,
    BigInteger,
    Field,
    Relationship,
    SQLModel,
    create_engine,
)


class Color(BaseModel):
    red: int
    green: int
    blue: int


class User(SQLModel, table

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Lolozendev
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
2 participants