my question is about way to get a select to parent model, with properly selectinload option, using pydantic response model.
For example:
from pydantic import BaseModel
class Parent(SQLModel, table=True):
id: UUID = sm.Field(UUID, primary_key=True)
childs:List[Child]= sm.Relationship(
back_populates="parent"
)
class Child(SQLModel, table=True):
parent_id:UUID=sm.Field()
sa_column=sm.Column(
sm.ForeignKey("parentr.id")
)
parent: "Parent" = sm.Relationship(
back_populates="childs"
)
#read schemas
class IChildRead(BaseModel):
id:UUID
class IParentReadWithChilds(BaseModel):
childs:List[IChildRead]
#result
select(Parent).options(selectinload(Parent.Childs))
The existance of property in pydantic model, tell us about necessity to use selectinload, of course the model can be very deep. I will be glad for any information.
I tried sqlmodel library, read documentation, but dont have answer for it.