Fixed #30421 -- Allowed symmetrical intermediate table for self-referential ManyToManyField.

This commit is contained in:
Nadège Michel 2019-04-19 18:12:04 +02:00 committed by Mariusz Felisiak
parent a9179ab032
commit 87b1ad6e73
11 changed files with 167 additions and 90 deletions

View file

@ -1537,6 +1537,11 @@ that control how the relationship functions.
add the descriptor for the reverse relationship, allowing
:class:`ManyToManyField` relationships to be non-symmetrical.
.. versionchanged:: 3.0
Specifying ``symmetrical=True`` for recursive many-to-many
relationships using an intermediary model was allowed.
.. attribute:: ManyToManyField.through
Django will automatically generate a table to manage many-to-many
@ -1549,6 +1554,16 @@ that control how the relationship functions.
:ref:`extra data with a many-to-many relationship
<intermediary-manytomany>`.
.. note::
Recursive relationships using an intermediary model and defined as
symmetrical (that is, with :attr:`symmetrical=True
<ManyToManyField.symmetrical>`, which is the default) can't determine
the reverse accessors names, as they would be the same. You need to set
a :attr:`~ForeignKey.related_name` to at least one of them. If you'd
prefer Django not to create a backwards relation, set ``related_name``
to ``'+'``.
If you don't specify an explicit ``through`` model, there is still an
implicit ``through`` model class you can use to directly access the table
created to hold the association. It has three fields to link the models.
@ -1624,12 +1639,6 @@ that control how the relationship functions.
foreign keys to the model, or you want to explicitly specify which two
Django should use.
Recursive relationships using an intermediary model are always defined as
non-symmetrical -- that is, with :attr:`symmetrical=False <ManyToManyField.symmetrical>`
-- therefore, there is the concept of a "source" and a "target". In that
case ``'field1'`` will be treated as the "source" of the relationship and
``'field2'`` as the "target".
.. attribute:: ManyToManyField.db_table
The name of the table to create for storing the many-to-many data. If this