summaryrefslogtreecommitdiff
path: root/docs/topics
diff options
context:
space:
mode:
authorClifford Gama <cliffygamy@gmail.com>2024-11-03 16:32:55 +0200
committerSarah Boyce <42296566+sarahboyce@users.noreply.github.com>2025-05-02 09:02:16 +0200
commit3c887e5e50ddcb84adef269e9558e603ca0ff620 (patch)
tree0d557c95f8640459121aed4d6d017ac48cce74bc /docs/topics
parent57c245199a0ea76e8155828a38c84192f39f18f4 (diff)
[5.2.x] Fixed #17461 -- Doc'd the presumed order of foreign keys on the intermediary model of a self-referential m2m.
Thanks Giannis Terzopoulos and Sarah Boyce for the reviews. Backport of 9d93e35c207a001de1aa9ca9165bdec824da9021 from main.
Diffstat (limited to 'docs/topics')
-rw-r--r--docs/topics/db/models.txt9
1 files changed, 6 insertions, 3 deletions
diff --git a/docs/topics/db/models.txt b/docs/topics/db/models.txt
index 98fb149b98..14233cbefd 100644
--- a/docs/topics/db/models.txt
+++ b/docs/topics/db/models.txt
@@ -533,9 +533,12 @@ There are a few restrictions on the intermediate model:
* For a model which has a many-to-many relationship to itself through an
intermediary model, two foreign keys to the same model are permitted, but
they will be treated as the two (different) sides of the many-to-many
- relationship. If there are *more* than two foreign keys though, you
- must also specify ``through_fields`` as above, or a validation error
- will be raised.
+ relationship. If :attr:`~.ManyToManyField.through_fields` is not specified,
+ the first foreign key will be taken to represent the source side of the
+ ``ManyToManyField``, while the second will be taken to represent the target
+ side. If there are *more* than two foreign keys though, you must specify
+ :attr:`~.ManyToManyField.through_fields` to explicitly indicate which foreign
+ keys to use, otherwise a validation error will be raised.
Now that you have set up your :class:`~django.db.models.ManyToManyField` to use
your intermediary model (``Membership``, in this case), you're ready to start