Hi Malcom and other,

> That would seem to only account for things that are directly attached to
> the current model, rather than more distant relations.

Yes, but that's enough for me.

> Have a look at what Model._collect_sub_objects() does -- or call it
> directly -- to see how Django goes about collecting all the objects for
> deletion. That method is seeded with an empty SortedDict() from
> Model.delete().

I looked at it. It ignores many to many relations.

self._meta.get_all_related_objects() does not return them.

BTW, why does django collect all sub objects? The SQL part "ON DELETE CASCADE" 
should
remove them.

Here is the unmodified django code:
"""
    def _collect_sub_objects(self, seen_objs):
        """
        Recursively populates seen_objs with all objects related to this object.
        When done, seen_objs will be in the format:
            {model_class: {pk_val: obj, pk_val: obj, ...},
             model_class: {pk_val: obj, pk_val: obj, ...}, ...}
        """
        pk_val = self._get_pk_val()
        if pk_val in seen_objs.setdefault(self.__class__, {}):
            return
        seen_objs.setdefault(self.__class__, {})[pk_val] = self

        for related in self._meta.get_all_related_objects():
            rel_opts_name = related.get_accessor_name()
            if isinstance(related.field.rel, OneToOneRel):
                try:
                    sub_obj = getattr(self, rel_opts_name)
                except ObjectDoesNotExist:
                    pass
                else:
                    sub_obj._collect_sub_objects(seen_objs)
            else:
                for sub_obj in getattr(self, rel_opts_name).all():
                    sub_obj._collect_sub_objects(seen_objs)
"""

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

Reply via email to