When implementing a ManyToMany relation with a 'through' table in an effort to add soft deletes across the pivot, the related objects returned from the related manager are not filtered out by their soft delete status. A basic example:
class Person(ArchiveMixin, models.Model):
events = models.ManyToManyField('Event', through='Participant', related_name='participants')
The Participant model also implements the ArchiveMixin:
class Participant(ArchiveMixin, models.Model):
An instance or Person with 9 participation (3 soft deleted) will return all 9 on calls to .events
>>> person.events.count()
9
As a workaround we can create an accessor method such as:
However, this is not ideal. I believe the problem could be that Django is using a different manager for the ManyToMany relations that is not considered by this mixin. I've had a dig around to see if I could extend the functionality to cover this scenario but I cannot find where this should go. Any insight on this would be appreciated.
When implementing a ManyToMany relation with a 'through' table in an effort to add soft deletes across the pivot, the related objects returned from the related manager are not filtered out by their soft delete status. A basic example:
The Participant model also implements the ArchiveMixin:
An instance or Person with 9 participation (3 soft deleted) will return all 9 on calls to .events
As a workaround we can create an accessor method such as:
Which will return correct results
However, this is not ideal. I believe the problem could be that Django is using a different manager for the ManyToMany relations that is not considered by this mixin. I've had a dig around to see if I could extend the functionality to cover this scenario but I cannot find where this should go. Any insight on this would be appreciated.
Many thanks.