Skip to content

Commit

Permalink
[1.7.x] Fixed #24432 -- Added docs for ManyToManyFields that reside i…
Browse files Browse the repository at this point in the history
…n and refer to the same model.

Backport of b9b8411 from master
  • Loading branch information
florisdenhengst authored and timgraham committed Mar 10, 2015
1 parent ee24ba2 commit 7a08c96
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion docs/ref/models/fields.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1380,14 +1380,26 @@ that control how the relationship functions.

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:
created to hold the association. It has three fields to link the models.

If the source and target models differ, the following fields are
generated:

* ``id``: the primary key of the relation.
* ``<containing_model>_id``: the ``id`` of the model that declares the
``ManyToManyField``.
* ``<other_model>_id``: the ``id`` of the model that the
``ManyToManyField`` points to.

If the ``ManyToManyField`` points from and to the same model, the following
fields are generated:

* ``id``: the primary key of the relation.
* ``from_<model>_id``: the ``id`` of the instance which points at the
model (i.e. the source instance).
* ``to_<model>_id``: the ``id`` of the instance to which the relationship
points (i.e. the target model instance).

This class can be used to query associated records for a given model
instance like a normal model.

Expand Down

0 comments on commit 7a08c96

Please sign in to comment.