#34594: KT doesn’t work across foreign keys
-------------------------------------+-------------------------------------
     Reporter:  Roman Odaisky        |                    Owner:  nobody
         Type:  New feature          |                   Status:  closed
    Component:  Database layer       |                  Version:  4.2
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:  wontfix
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

 * status:  new => closed
 * type:  Bug => New feature
 * resolution:   => wontfix


Comment:

 > The problem is in the SQL that KT generates: `("parent"."id" #>>
 ARRAY['data','some_string']) AS "x"`, which, it seems, is the result of
 KeyTextTransform.from_lookup taking all the double-underscore-separated
 parts of the argument of KT to mean JSON lookups and not other possible
 lookups such as foreign keys.

 Thanks for the report, however, it works exactly as
 
[https://docs.djangoproject.com/en/stable/topics/db/queries/#django.db.models.fields.json.KT
 documented] ''"You can use the double underscore notation in `lookup` to
 chain dictionary key and index transforms."'', so it's not a bug but a new
 feature request. As far as I'm aware we don't want to complicate it, and
 you can annotate nested `JSONField` to make it work, e.g.
 {{{
 Child.objects.annotate(data=F("parent__data"), x=KT("data__some_string"))
 }}}
 You can start a discussion on DevelopersMailingList if you don't agree.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34594#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/010701884be672cf-248d10e5-ccc4-4ade-b924-9bc8b68d4c5a-000000%40eu-central-1.amazonses.com.

Reply via email to