Changes between Version 1 and Version 2 of Ticket #33176


Ignore:
Timestamp:
Oct 7, 2021, 8:47:07 AM (3 years ago)
Author:
Mauro Crociara
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #33176 – Description

    v1 v2  
    7373
    7474I'm doing something wrong?
     75
     76Using base_manager works to:
     77
     78
     79{{{#!python
     80Task._meta.base_manager.select_related(None).prefetch_related(None).filter(candidate=candidate, planning_rsc__isnull=False).only('pk').order_by('-planning_rsc', 'task_type_two')
     81}}}
     82{{{#!sql
     83SELECT "candidates_tasks"."id"
     84FROM "candidates_tasks"
     85WHERE ("candidates_tasks"."candidate_id" = 77677 AND "candidates_tasks"."planning_rsc" IS NOT NULL)
     86ORDER BY "candidates_tasks"."planning_rsc" DESC, "candidates_tasks"."task_type_two" ASC
     87}}}
     88
     89And
     90
     91{{{#!python
     92Task._meta.base_manager.select_related(None).prefetch_related(None).filter(candidate=candidate, planning_rsc__isnull=False).only('pk').order_by('task_type_two', '-planning_rsc').query)
     93}}}
     94{{{#!sql
     95SELECT "candidates_tasks"."id"
     96FROM "candidates_tasks"
     97WHERE ("candidates_tasks"."candidate_id" = 77677 AND "candidates_tasks"."planning_rsc" IS NOT NULL)
     98ORDER BY "candidates_tasks"."task_type_two" ASC, "candidates_tasks"."planning_rsc" DESC
     99}}}
     100
     101I cannot use **only** with **object**
     102
     103
     104{{{#!python
     105Task.objects.filter(candidate=candidate, planning_rsc__isnull=False).only('pk').order_by('-planning_rsc', 'task_type_two')
     106}}}
     107>django.core.exceptions.FieldError: Field Task.candidate cannot be both deferred and traversed using select_related at the same time.
     108
     109Then try with **values_list**
     110
     111
     112{{{#!python
     113Task.objects.filter(candidate=candidate, planning_rsc__isnull=False).values_list('pk').order_by('-planning_rsc', 'task_type_two')
     114}}}
     115{{{#!sql
     116SELECT "candidates_tasks"."id"
     117FROM "candidates_tasks"
     118         LEFT OUTER JOIN "candidates_technologiestwo"
     119                         ON ("candidates_tasks"."id" = "candidates_technologiestwo"."task_id")
     120         INNER JOIN "candidates_candidates"
     121                    ON ("candidates_tasks"."candidate_id" = "candidates_candidates"."location_ptr_id")
     122         LEFT OUTER JOIN "iliad_operators" ON ("candidates_candidates"."landlord_operator_id" = "iliad_operators"."id")
     123         LEFT OUTER JOIN "candidates_tower_companies"
     124                         ON ("candidates_candidates"."tower_company_id" = "candidates_tower_companies"."id")
     125         INNER JOIN "iliad_locations" ON ("candidates_candidates"."location_ptr_id" = "iliad_locations"."id")
     126WHERE ("candidates_tasks"."candidate_id" = 77677 AND "candidates_tasks"."planning_rsc" IS NOT NULL)
     127GROUP BY "candidates_tasks"."id"
     128ORDER BY "candidates_tasks"."planning_rsc" DESC
     129}}}
     130
     131`task_type_two` is missing in **order_by** clause
Back to Top