On Feb 5, 3:13 pm, Alex Gaynor <alex.gay...@gmail.com> wrote:
> On Thu, Feb 5, 2009 at 3:09 PM, George Sakkis <george.sak...@gmail.com>wrote:
>
>
>
>
>
> > Hello,
>
> > I am looking at the raw sql executed when I run a delete or update on
> > a QuerySet and it appears that it does a redundant "select *" for the
> > queryset before the actual delete/update. For example
>
> > delete_ids = (108, 107, 106)
> > qs = MyModel.objects.filter(pk__in=delete_ids)
> > print connection.queries   # shows no queries
> > qs.delete()
> > print connection.queries # shows two queries, a select followed by a
> > delete
>
> > Am I missing something or Is this supposed to work like this, and if
> > so why ?
>
> > George
>
> No you are correct, and this intended behavior.  This is because Django
> emulates the CASCADE behavior for DBs which don't support it, so it needs to
> build up the list of related objects internally, to do this it needs the
> objects themselves.
>
> To get a better idea of what I'm describing take a look at the 
> source:http://code.djangoproject.com/browser/django/trunk/django/db/models/q...

Thanks, that was quick! Ok, this clears up things, though I'm
wondering if it could be smarter and check if there are no related
objects based on the schema alone, and if that's the case avoid the
redundant select. I can open a feature request ticket If that makes
sense.

George
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to