#35956: Add composite foreign keys
-------------------------------------+-------------------------------------
     Reporter:  Csirmaz Bendegúz     |                    Owner:  (none)
         Type:  New feature          |                   Status:  new
    Component:  Database layer       |                  Version:  dev
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:  Accepted
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Comment (by Csirmaz Bendegúz):

 Replying to [comment:2 Mariusz Felisiak]:
 > Replying to [ticket:35956 Csirmaz Bendegúz]:
 > > My proposal is to add 2 parameters to `ForeignKey`: `from_fields` and
 `to_fields`.
 >
 > Do we need these parameters? `CompositePrimaryKey` is always a primary
 key so its fields should be detected automatically, IMO, the following
 example should work:
 > {{{#!python
 > class Release(models.Model):
 >     pk = models.CompositePrimaryKey("version", "name")
 >     version = models.IntegerField()
 >     name = models.CharField(max_length=20)
 >
 >
 > class RefRelease(models.Model):
 >     release = models.ForeignKey("Release", models.CASCADE)
 > }}}

 The issue with this example is `RefRelease` must have 2 fields matching
 the `CompositePrimaryKey` (an `IntegerField()` and a
 `CharField(max_length=20)`).
 So `release` would need to create 2 fields implicitly and I'm not sure if
 this would be a good direction?
 We should allow sharing fields between composite foreign keys, for example
 in a multitenant app, the `tenant_id` should be shared between multiple
 composite foreign keys.
 Let me know what you think, I'm happy to consider any alternatives.
-- 
Ticket URL: <https://code.djangoproject.com/ticket/35956#comment:4>
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 visit 
https://groups.google.com/d/msgid/django-updates/010701940e00b479-2299dff4-1868-4e16-92f2-ae9a6f2d76f4-000000%40eu-central-1.amazonses.com.

Reply via email to