2021年1月25日星期一

Django 3.1 bug: Reflexive Many-to-many relations. Add creates two relationships instead of one

in the model called Business:

sold_at_businesses = models.ManyToManyField('self', db_table='businesses_to_sold_at_businesses', related_name='businesses_selling')  

test code - ms is a Business instance.

    ms.sold_at_businesses.clear()      b = Business.objects.get(slug="test-business")      if b:          ms.sold_at_businesses.add(b)  

Bug: This single add call adds two entries to the pivot table. ms -> b and b -> ms

screenshot of businesses_to_sold_at_businesses table after a single .add call:

enter image description here

Why are two connections being created when I clearly specify only one? this seems like a reflexive model bug in Django.

https://stackoverflow.com/questions/65894735/django-3-1-bug-reflexive-many-to-many-relations-add-creates-two-relationships January 26, 2021 at 09:30AM

没有评论:

发表评论