Replies: 1 comment
-
I found this problem as well. In this scenario, I update the data manually. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
First Check
Commit to Help
Example Code
Description
Thanks a lot for your awesome work with sqlmodel. I really respect the work and effort that went into such a huge undertaking.
In my Project, i use a composition-based approach in my models. There are several differently structured but related models in a single table. The approach uses additional table models, where the primary key is a foreign_key of the base table model, like a component of the base model as an optional relation. This way, i can enforce a structure for a concrete type (like a GoodHero has a GoodHero component), but can have one table with one relation to another table (like a Hero can still be a member of a Team).
I considered several alternatives to this approach:
I really like the approach used in my example, because i can easily define which attributes belong to a concrete type, and even define update models for them to control what should be changable. Also adding new types is easy, because i can put them into a new component, without much additional changes to the model. Relations to other Entities are handled in the base table, so that other entities dont need knowledge about specific (sub-)types.
My problem lies in updating this design: When trying to use my defined update model "HeroUpdate" with sqlmodel_update, the attributes of the component are not updated, even though they are present in the dictionary which is passed to sqlmodel_update. This is the example in the function "variant_1".
I built a workaround for this in the example in function "variant_2", but this feels like a hack, and i am not sure if this could lead to other problems.
Is there a way to handle this properly within sqlmodel? Maybe there could be a flag like "include_nested_models" or something like that. Also, if you can see a design issue with this, im happy to receive feedback for that.
Operating System
macOS
Operating System Details
No response
SQLModel Version
0.0.16
Python Version
Python 3.11.7
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions