First Check
Commit to Help
Example Code
from typing import List
from sqlalchemy import func
from sqlalchemy import select as sa_select
from sqlalchemy.orm import column_property
from sqlmodel import create_engine, Field, Relationship, SQLModel
class Hero(SQLModel, table=True):
name: str = Field(primary_key=True)
team_name: str = Field(foreign_key="team.name")
team: "Team" = Relationship(back_populates="heroes")
class Team(SQLModel, table=True):
name: str = Field(primary_key=True)
heroes_count = column_property(
sa_select(func.count(Hero.team_name))
.where(Hero.team_name == name)
.correlate_except(Hero)
.scalar_subquery()
)
heroes: List["Hero"] = Relationship(back_populates="team")
if __name__ == "__main__":
engine = create_engine("sqlite:///test.db")
SQLModel.metadata.create_all(engine)
Description
sqlalchemy.exc.InvalidRequestError: When initializing mapper mapped class Hero->hero, expression 'Team' failed to locate a name ('Team').
If this is a class name, consider adding this relationship() to the <class '__main__.Hero'> class after both dependent classes have been defined.
Operating System
macOS
Operating System Details
No response
SQLModel Version
0.0.6
Python Version
Python 3.9.6
Additional Context
No response
First Check
Commit to Help
Example Code
Description
sqlalquemy.orm.column_property(https://docs.sqlalchemy.org/en/14/orm/mapped_sql_expr.html#using-column-property)sqlalquemy.exc.InvalidRequestErrorOperating System
macOS
Operating System Details
No response
SQLModel Version
0.0.6
Python Version
Python 3.9.6
Additional Context
No response