tickets: 9519
This data as json
id | created | changetime | last_pulled_from_trac | stage | status | component | type | severity | version | resolution | summary | description | owner | reporter | keywords | easy | has_patch | needs_better_patch | needs_tests | needs_docs | ui_ux |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
9519 | 2008-11-04 19:53:07 | 2016-11-22 16:25:16 | 2022-03-06 03:45:05.848882 | Accepted | new | Database layer (models, ORM) | New feature | Normal | dev | Add QuerySet.bulk_delete() that issues only a single SQL query | Example: {{{ #!python from django.db import models class MyModel(models.Model): my_id = models.IntegerField(primary_key=True) col1 = models.IntegerField() col2 = models.CharField(max_length=1) col3 = models.TextField() class Meta: unique_together = ('my_id', 'col1', 'col2') # "Fake" a multi-part primary key # This works for creating all 3, as force_insert is used in create() MyModel.objects.create(my_id=1, col1=5, col2='a', col3='foo') MyModel.objects.create(my_id=1, col1=5, col2='b', col3='bar') MyModel.objects.create(my_id=1, col1=10, col2='a', col3='baz') MyModel.objects.filter(my_id=1, col1=5).delete() }}} This deletes all of the objects created above, since deletion is done only based on model._meta.pk. This is fine, except when you are using multi-part primary keys and emulating that pkey as suggested in #373. In my opinion, the delete operation should be executed with respect to the filter(), extra(), etc which were previously performed on the QuerySet. This is, in a way, a part of ticket #373, but I believe it can be viewed as a completely separate issue. In some cases, you do want to delete based on columns other than the primary key. Why build a list of all of those primary keys when you've already specified all of the qualifiers in a filter()? | nobody | Tarken | database, queryset, delete | 0 | 0 | 0 | 0 | 0 | 0 |