#29900: ForeignKey foo with to_field=bar option: Accessor should be called 
foo_bar
not foo_id
-------------------------------------+-------------------------------------
     Reporter:  Paul Zeinlinger      |                    Owner:  nobody
         Type:                       |                   Status:  new
  Cleanup/optimization               |
    Component:  Database layer       |                  Version:  2.1
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:  to_field             |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Paul Zeinlinger):

 Well, you are absolutely right about the breaking change. It would
 certainly require a deprecation period. But since {{{
 f'{field.name}_{field.target_field.name}'}}} is not in use right now, we
 could alias it and keep backward compatibility in this way.
 IMHO your example demonstrates exactly, why we should not keep doing it
 this way. In your example, we don't have any information about the
 contents or the type of user_id. It could as well be a UUID, a text field
 with the user's bio or an integer.

 In case of a pk, we know that there's only one in a table. But ForeignKeys
 with to_fields can reference any field, not just the primary key (as long
 as it is unique). So I guess, it's not practical to compare those two
 cases.

 Let's consider another example:
 If we have an API serving messages as json to the user, but we don't want
 to disclose the primary key of the user (eg. for security reasons), then
 we could serve a json with a {.... user_uuid: XXX} entry. However, the api
 user wouldn't be able to set the corresponding database user directly - he
 would need to submit the users UUID, we would need to look it up in the
 db, get the username and set it, respectively (that's 3 lookups compared
 to just one).

 I can't see a point, why this would be more intuitive than just having a
 corresponding field.
 But I might be wrong :-) It's just an idea.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/29900#comment:2>
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/069.d3af00c32259855e59eb0443200760e2%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to