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
When using values_list through a relationship ormar is return all non-nullable fields and the taking the first one as the flattened value, which is the wrong field/values.
An example, say I have a list of car ids, and I want to find the set of owners for that set of cars. Each car has a garage, each garage has an owner. I only want the owner_id's for efficiency sake.
Car has a bunch of non-nullable fields as does Garage and Owner, hence why I want to use values_list to query raw data and not hydrate actual models
When this is executed I actually get the whole of the Car and Garage models queried for (I can see the SELECTs for these columns in the SQL), and then https://github.com/collerek/ormar/blob/master/ormar/queryset/queryset.py#L640 is just grabbing the first value, which happens to be the Car.id not anything to do with Car.garage.owner.id.
I've tried using fields_exclude to explicitly remove non-nullable fields but it doesn't work. I've tried a combination of flatten and exclude_through with similar results.
As far as I can tell, using values_list isn't allowing me to bypass non-nullable fields? Is there something I've missed, or not understood about querying raw data like this?
The text was updated successfully, but these errors were encountered:
jonfinerty
changed the title
Values_list querying and returning wrong flattened datavalues_list querying and returning wrong flattened data
Apr 18, 2023
When using
values_list
through a relationship ormar is return all non-nullable fields and the taking the first one as the flattened value, which is the wrong field/values.An example, say I have a list of car ids, and I want to find the set of owners for that set of cars. Each car has a garage, each garage has an owner. I only want the owner_id's for efficiency sake.
Car
has a bunch of non-nullable fields as doesGarage
andOwner
, hence why I want to usevalues_list
to query raw data and not hydrate actual modelsWhen this is executed I actually get the whole of the
Car
andGarage
models queried for (I can see theSELECT
s for these columns in the SQL), and then https://github.com/collerek/ormar/blob/master/ormar/queryset/queryset.py#L640 is just grabbing the first value, which happens to be theCar.id
not anything to do withCar.garage.owner.id
.I've tried using
fields_exclude
to explicitly remove non-nullable fields but it doesn't work. I've tried a combination offlatten
andexclude_through
with similar results.As far as I can tell, using
values_list
isn't allowing me to bypass non-nullable fields? Is there something I've missed, or not understood about querying raw data like this?The text was updated successfully, but these errors were encountered: