diff options
| author | Russell Keith-Magee <russell@keith-magee.com> | 2009-02-23 14:47:59 +0000 |
|---|---|---|
| committer | Russell Keith-Magee <russell@keith-magee.com> | 2009-02-23 14:47:59 +0000 |
| commit | 542709d0d1796326dd1edacf32fc1198cfad2869 (patch) | |
| tree | 40578c8972862606d7ddb0dad9c7e0e163b160e0 /docs | |
| parent | 4bd24474c02a6f3c70e8111ac262fabf2fc5f454 (diff) | |
Fixed #10182 -- Corrected realiasing and the process of evaluating values() for queries with aggregate clauses. This means that aggregate queries can now be used as subqueries (such as in an __in clause). Thanks to omat for the report.
This involves a slight change to the interaction of annotate() and values() clauses that specify a list of columns. See the docs for details.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@9888 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/topics/db/aggregation.txt | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/docs/topics/db/aggregation.txt b/docs/topics/db/aggregation.txt index 51942d9a1c..a861959e66 100644 --- a/docs/topics/db/aggregation.txt +++ b/docs/topics/db/aggregation.txt @@ -284,9 +284,6 @@ two authors with the same name, their results will be merged into a single result in the output of the query; the average will be computed as the average over the books written by both authors. -The annotation name will be added to the fields returned -as part of the ``ValuesQuerySet``. - Order of ``annotate()`` and ``values()`` clauses ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -303,12 +300,21 @@ output. For example, if we reverse the order of the ``values()`` and ``annotate()`` clause from our previous example:: - >>> Author.objects.annotate(average_rating=Avg('book__rating')).values('name') + >>> Author.objects.annotate(average_rating=Avg('book__rating')).values('name', 'average_rating') This will now yield one unique result for each author; however, only the author's name and the ``average_rating`` annotation will be returned in the output data. +You should also note that ``average_rating`` has been explicitly included +in the list of values to be returned. This is required because of the +ordering of the ``values()`` and ``annotate()`` clause. + +If the ``values()`` clause precedes the ``annotate()`` clause, any annotations +will be automatically added to the result set. However, if the ``values()`` +clause is applied after the ``annotate()`` clause, you need to explicitly +include the aggregate column. + Aggregating annotations ----------------------- |
