You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I used the GitHub search to find a similar question and didn't find it.
I searched the SQLModel documentation, with the integrated search.
I already searched in Google "How to X in SQLModel" and didn't find any information.
I already read and followed all the tutorial in the docs and didn't find an answer.
I already checked if it is not related to SQLModel but to Pydantic.
I already checked if it is not related to SQLModel but to SQLAlchemy.
Commit to Help
I commit to help with one of those options 👆
Example Code
fromtypingimportOptionalfromsqlmodelimportField, Session, SQLModel, create_engine, RelationshipclassHero(HeroBase, table=True):
id: Optional[int] =Field(default=None, primary_key=True)
name: strsecret_name: strage: int|None=NoneclassTeamBase(SQLModel):
titles: list[str]
heroes: list["Hero"]
classTeam(TeamBase, table=True):
id: Optional[int] =Field(default=None, primary_key=True)
# titles: list[str] = Field(sa_column=Column(ARRAY(String), nullable=True))# heroes: list["Hero"] = Relationship(back_populates="heroes")# I would like titles array and Heroes Relationship# to be automatically recognized and mapped based on TeamBase modelhero_1=Hero(name="Deadpond", secret_name="Dive Wilson")
engine=create_engine("sqlite:///database.db")
SQLModel.metadata.create_all(engine)
withSession(engine) assession:
session.add(hero_1)
session.commit()
session.refresh(hero_1)
print(hero_1)
Description
As noted in the code comments, I'd like list[str] and list[Hero] to be automatically recognized by the table model based on types in BaseModel without need to redeclare explicit Field and Relationship. This seems to be against the concept of SQLModel for me.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
First Check
Commit to Help
Example Code
Description
As noted in the code comments, I'd like list[str] and list[Hero] to be automatically recognized by the table model based on types in BaseModel without need to redeclare explicit Field and Relationship. This seems to be against the concept of SQLModel for me.
Operating System
Linux
Operating System Details
No response
SQLModel Version
0.0.14
Python Version
3.10
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions