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 want to create an SQLModel base class that contains a relationship which i can inherit.
in the example there is a HeroBase which is inherited by AnimalHero and RobotHero. It inherits the columns correctly but with the relationships, i need to use sqlalchemy.orm.declared_attr, sqlalchemy.orm.relationship and # type: ignore so the type checker doesnt get mad.
then in insertion i need to first insert the teams, commit, then link the heroes via the team_id manually instead of doing AnimalHero(name="chickenman", species="chickens", team=peace), so the current way is very similar to this
Wanted Solution
I just want to inherit the relationship provided by SQLModel.Relationship and doing the insertion this way.
The reason for me to go to this route is to implement generic tables/associations and tried to look for examples in SQLAlchemy and tried to use SQLAlchemy-Utils generic_relationship with Relationship(sa_relationship=generic_relationship("object_id", "object_type")), although the later works for insertion, it doesnt work when you try to getattr the relationship after selection.
The wanted code is reasonable considering this is my second day using SQLModel and it feels intuitive to do it that way.
The text was updated successfully, but these errors were encountered:
First Check
Commit to Help
Example Code
Description
I want to create an SQLModel base class that contains a relationship which i can inherit.
in the example there is a
HeroBase
which is inherited byAnimalHero
andRobotHero
. It inherits the columns correctly but with the relationships, i need to usesqlalchemy.orm.declared_attr
,sqlalchemy.orm.relationship
and# type: ignore
so the type checker doesnt get mad.then in insertion i need to first insert the teams, commit, then link the heroes via the
team_id
manually instead of doingAnimalHero(name="chickenman", species="chickens", team=peace)
, so the current way is very similar to thisWanted Solution
I just want to inherit the relationship provided by
SQLModel.Relationship
and doing the insertion this way.Wanted Code
Alternatives
Using directly
SQLAlchemy
instead ofSQLModel
Operating System
Linux
Operating System Details
No response
SQLModel Version
0.0.4
Python Version
Python 3.9.8
Additional Context
The reason for me to go to this route is to implement generic tables/associations and tried to look for examples in SQLAlchemy and tried to use SQLAlchemy-Utils generic_relationship with
Relationship(sa_relationship=generic_relationship("object_id", "object_type"))
, although the later works for insertion, it doesnt work when you try to getattr the relationship after selection.The wanted code is reasonable considering this is my second day using SQLModel and it feels intuitive to do it that way.
The text was updated successfully, but these errors were encountered: