How to efficiently query for a subset of required fields #363
-
I have an But in another route I want to query just a subset of the fields in the database for the same table to make the query/serialization more efficient. As explained here: https://collerek.github.io/ormar/queries/select-columns/
So I can't reuse the same I tried to create another
What is the best way to make queries for a subset of fields for which there is an existing model with required fields defined? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
This one is quite tricky -> cause if you want to have multiple models operating on one table and each of them has different required columns you would end up with some of the models that should be read only. Cause if you insert a row without columns that are required by the other model you wouldn't be able to read this row with another model as the data would be corrupted (required columns would be null). The other solution is that each model is still storing the data in the same table, but each row is "marked" as one of the models, so the data is stored in the same table but rows are actually separated and operates on their own rows only. Both of those scenarios are kinds of inheritance that are not supported as of now, but that would also not solve your use case as you want to read the same rows with different models. The recommended solution is to use either |
Beta Was this translation helpful? Give feedback.
This one is quite tricky -> cause if you want to have multiple models operating on one table and each of them has different required columns you would end up with some of the models that should be read only.
Cause if you insert a row without columns that are required by the other model you wouldn't be able to read this row with another model as the data would be corrupted (required columns would be null).
The other solution is that each model is still storing the data in the same table, but each row is "marked" as one of the models, so the data is stored in the same table but rows are actually separated and operates on their own rows only.
Both of those scenarios are kinds of inheritance …