# If i am using through table in ManyToMany field what is point of having ManyToManyField?

**URL:** <https://forum.djangoproject.com/t/if-i-am-using-through-table-in-manytomany-field-what-is-point-of-having-manytomanyfield/2098>\
**Category:** Using Django\
**Created:** [April 24, 2020, 9:31pm UTC](https://forum.djangoproject.com/t/if-i-am-using-through-table-in-manytomany-field-what-is-point-of-having-manytomanyfield/2098 "2020-04-24T21:31:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![HitanshiMehta](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/hitanshimehta/32/1069_2.png) [@HitanshiMehta](https://forum.djangoproject.com/u/HitanshiMehta)\
**Post date:** [April 24, 2020, 9:31pm UTC](https://forum.djangoproject.com/t/if-i-am-using-through-table-in-manytomany-field-what-is-point-of-having-manytomanyfield/2098/1 "2020-04-24T21:31:23Z")

</div>

Hello there,  
this is my first question in django forum.  
I have two modela Publication and Article as follow.

```
class Publication(models.Model):
    title = models.CharField(max_length=30)

class Article(models.Model):
    headline = models.CharField(max_length=100)
    publications = models.ManyToManyField(Publication,
                                          related_name="published_article",
                                          through='articles_publication',
                                          through_fields=('article', 'publication'))

```

In Article model I have `ManyToMany` publications field which is pointing to the article\_publication model which is as follow.

```
class articles_publication(models.Model):
    articles_publication_id = models.AutoField(primary_key=True, db_column='article_publication_id')
    article = models.ForeignKey(Article, on_delete=models.SET_NULL, null=True)
    publication = models.ForeignKey(Publication, on_delete=models.SET_NULL, null=True)

```

Now, In this scenario, we are creating an individual model to maintain `ManyToMany` relation between Article and publication. So, why we should have a field `publications` in Article Model. Following Article model will perform the same task.

```
class Article(models.Model):
    headline = models.CharField(max_length=100)

```

Specifying the` ManyToMany` field provides any advantage?  
Thanks in advance.

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [April 26, 2020, 1:34am UTC](https://forum.djangoproject.com/t/if-i-am-using-through-table-in-manytomany-field-what-is-point-of-having-manytomanyfield/2098/2 "2020-04-26T01:34:03Z")

</div>

What you’re getting here is the ability to implicitly join through that intermediate table.

The [Many-to-many relationship](https://docs.djangoproject.com/en/3.0/topics/db/examples/many_to_many/#many-to-many-relationships) page documents a lot of the features available that would be lost without it.

For example, when you have the ManyToMany field defined, you can define the relationship using something like `a1.publications.add(p1)`, rather than `articles_publication(article=a1, publication=p1)`  
Also, and perhaps more clear, you can say `a1.publications.all()` rather than something like `Publication.objects.filter(articles_publication__article=a1)` (I’m just winging this, I have no idea if this is exactly the right query for this example.)

So yes, I’d say you’re technically correct. I’m not aware of any specific situation where a ManyToManyField is _required_ - in fact, I worked on a system where they were prohibited.  
(It was an older version of Django - before 1.6 I believe - it was before the ManyToManyField could specify a ‘through’ table with additional fields. Since we relied heavily on many-to-many relationships with additional data (usually dates tracking when the relationship was applied), we couldn’t use the ManyToManyField in those situations.)

Anyway, so while I don’t believe they’re ever _required_, they do make writing some queries oh-so-much easier.
