Invalid result in many to many list if through instance is soft deleted
See original GitHub issueHi guys. I have below models
class BaseModel(SafeDeleteModel):
_safedelete_policy = SOFT_DELETE_CASCADE
class Student(BaseModel):
full_name = models.CharField(max_length=150)
class School(BaseModel):
name = models.CharField(max_length=150)
students = models.ManyToManyField(
Student,
through='SchoolStudent',
)
class SchoolStudent(BaseModel):
student = models.ForeignKey(Student, on_delete=models.CASCADE)
school = models.ForeignKey(School, on_delete=models.CASCADE)
I create a relationship between a school and a student, and then I delete it. but the below event occurs
school = School.objects.create(name='new_school')
student = Student.objects.create(full_name='Tom Smith')
school.students.add(student)
# delete all relationship
SchoolStudent.objects.all().delete()
school.students.all()
<QuerySet [<Student: Tom Smith>]>
As you see. we get wrong results. we deleted the relationship but we get the queryset. Have you got any idea to solve the issue?
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Hibernate left join fetch to soft-deleted entity mapped with ...
Hibernate left join fetch to soft-deleted entity mapped with @ManyToMany association generates invalid query?
Read more >Soft delete with EF Core - Medium
In this article you will learn how to implement soft delete capability in your application and how would it impact on querying of...
Read more >How to Implement a Soft Delete with Spring JPA - Baeldung
A common way to implement soft delete is to add a field that will indicate whether data has been deleted or not. This...
Read more >Working With Soft Deletes in Laravel 8 and 9 (By Example)
The annoying thing about deleting data from a database is that it's gone forever. We can't even look at the data to see...
Read more >EF Core In depth – Soft deleting data with Global Query Filters
This type of feature is known as soft delete and it has many good ... For instance, here is a Book entity with...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Correct. As a workaround for your situation, you can just do something like:
But it will be difficult to remember not to use
ManyRelatedManager
with these objects, and likely lead to bugs at some point.I’ll keep looking at this and see if I can find any solution, and if so submit a PR. I decided to adopt this library in a project I’m working on, largely because of its strong tests and handling of tricky situations like this, so I’d love to have this one handled in an intuitive way.
Thanks for your work & responsiveness @Gagaro
So because
create_forward_many_to_many_manager()
create a new manager inheriting from our own and not the other way around, it seems complicated to fix this.I added a test which reproduce this but it fails for now.