4 | | - Group by the primary key of the table in the query by default. The group by will need to be appended by functionally dependent columns as many databases need this. This means that we can add any column from the same table to the group by, or any column from any table pointed by direct foreign key or reverse one to one field. |
5 | | - Group by the user's defined .values() call. Possibly allow extending it by functionally dependent columns. That is, if some table's primary key is in the values() list, then allow extension from that primary key along foreign keys and o2ofields. |
6 | | - If any other column is needed in the group by, then error out. This means that: `CPUJob.objects.values('project').annotate(usage=Sum('cpu_usage'), jobs=Count('id')).order_by('date')` is an error. |
| 4 | 1. Group by the primary key of the table in the query by default. The group by will need to be appended by functionally dependent columns. This means that we add any column from the same table to the group by, or any column from any table pointed by direct foreign key or reverse one to one field to the group by (there are some database specific optimizations we could use here). |
| 5 | 2. The above rule will be overridden when using .values() queries. In that case, group by the user's defined .values() call. Possibly allow extending it by functionally dependent columns. That is, if some table's primary key is in the values() list, then allow extension from that primary key along foreign keys and o2ofields similarly to 1). |
| 6 | 3. If any other column is needed in the group by, then error out. This means that: `CPUJob.objects.values('project').annotate(usage=Sum('cpu_usage'), jobs=Count('id')).order_by('date')` is an error. |