If I have some models like so:
from django.db import models
class X(models.Model):
y = models.ForeignKey(Y)
... other fields ...
class Y(models.Model):
... some fields ...
... and I do a query like so:
X.objects.all().values('y')
... I get back a list of dictionaries that contain Y ID integers.
If I do a query like so:
X.objects.all().values('y_id')
...I get back a similar result, except for the keys in the dictionaries.
My proposal is to differentiate between those two calls and in the former case, instead of returning the same results as the latter case, return Y model objects.
Not only would this produce results that are more indicative of what the query is asking for, but it would extend the ORM in at least one area:
http://stackoverflow.com/questions/30113766/aggregrate-query-with-related-models-not-just-related-id-valuesThose kinds of aggregrate queries would be possible.
As far as backwards compatibility is concerned, the old behaviour could occur with no key word argument to the values() call, but if a keyword argument like so:
X.objects.all().values('y', select_related=True)
...is specified, then my proposed behaviour could be executed.
What do you think?