#28824: Allow different Foreign Keys to share same underlying DB column
-------------------------------------+-------------------------------------
     Reporter:  klass-ivan           |                    Owner:  nobody
         Type:  New feature          |                   Status:  new
    Component:  Database layer       |                  Version:  1.11
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:  foreigh key,         |             Triage Stage:
  db_column,                         |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Josh Smeaton):

 I'm struggling to see where the value for this change would be, and how
 common a situation this really is. I think the benefit of supporting this
 would be outweighed by users that are incorrectly duplicating keys on
 their models with copy/paste and running into legitimate issues.

 Further, I believe you can (probably) get similar behaviour working if you
 reverse the location of your keys, and switch to using OneToOne. I haven't
 tested this myself, but I think this would work:

 {{{
 class A(Model):
     uid = CharField(unique=True)
     c = OneToOneField(to=C, to_field='uid', db_column='uid', null=True)

 class B(Model):
     uid = CharField(unique=True)
     c = OneToOneField(to=C, to_field='uid', db_column='uid', null=True)

 class C(Model):
    # other fields
    uid  = CharField(unique=False)

 c = get_c(..)
 c.a # fine
 c.b # fine
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/28824#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/068.96e368e96ad57ffcdf5fb1896c0c7fbc%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to