Skip to content
Discussion options

You must be logged in to vote

You shouldn't use models with table=True for validation. Such models bypass some validation and relationships are not validated.

Instead you should create new ChildPublic model and use it for validation\serialization:

class ChildBase(SQLModel):
    id: Optional[int] = Field(default=None, primary_key=True)
    name: str

class Child(ChildBase, table=True):
    hero_id: int = Field(foreign_key="hero.id")
    hero: Hero = Relationship(back_populates="children")

class ChildPublic(ChildBase):
    hero: HeroPublic

Runnable code example in the details:

from typing import Optional, List

from sqlmodel import Field, Session, SQLModel, create_engine, select, Relationship


class HeroBase(SQLModel)…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
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