-
-
Notifications
You must be signed in to change notification settings - Fork 714
Is it possible to instantiate a SQLModel object with relationships from a dict
type?
#342
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
One thing I don't understand here is how FastAPI instantiates SQLModel objects from the JSON request object. I think there must be support for what I want to achieve, it's just not easily accessible or well documented. |
Hm I thought it works, am using I do have them in my return values. |
I am noticing a similar issue, even doing Hero(team=Team(...)).team will give a Hero object has no attribute team.. |
I just ran into this same issue. Drove me nuts trying to figure it out. I imagine many JSON posts to FastAPI have such nested statements so I'm surprised that this is an issue. I keep thinking I must be doing something wrong. |
I think this is essentially a duplicate of this: I agree that this is worthwhile, but I suggest closing this duplicate issue. |
Did you ever find a way around this issue? |
First Check
Commit to Help
Example Code
Description
In Pydantic it is possible to instantiate objects directly from dicts (i.e. JSON) via
ClassName(**dict)
. This also works for objects with nested objects (i.e. relationships in SQLModel). Is it possible to do the same in SQLModel? I would like to take a JSON like{"id": 123, "relationship_obj": {"id": 456, ...}}
and have SQLModel correctly create the relationship model based on the type of the field & the key of the dict passed in.The error received is:
Operating System
Linux
Operating System Details
No response
SQLModel Version
0.0.6
Python Version
Python 3.9.5
Additional Context
No response
The text was updated successfully, but these errors were encountered: