On Dec 12, 4:53 pm, Wilfred Hughes <wilf...@potatolondon.com> wrote: > > [Django] is (sort of) _emulating_ SQL cascading deletes, but it does so in > > a way that doesn't assume anything at all from the backend. > > I'm not sure this is correct. If I define the following models: <SNIP> > In [1]: from vortaro.models import Person, Car > > In [2]: p = Person.objects.create(name='bob') > > In [3]: c = Car.objects.create(name='robin reliant', owner=p)
At this point you have a person, and a related car in DB. > In [4]: p.delete() > > In [5]: Car.objects.all() > Out[5]: [] <SNIP> Delete starts here: > {'sql': u'SELECT "vortaro_car"."id", "vortaro_car"."name", > "vortaro_car"."owner_id" FROM "vortaro_car" WHERE > "vortaro_car"."owner_id" IN (1)', > 'time': '0.001'}, We are deleting person with id 1. Here we fetch related cars. > {'sql': u'DELETE FROM "vortaro_car" WHERE "id" IN (1)', 'time': > '0.000'}, Now this is the emulated cascade. Above we found one car with id 1. Now we are deleting it. > {'sql': u'DELETE FROM "vortaro_person" WHERE "id" IN (1)', 'time': > '0.000'}, All related objects have been deleted, so now we delete the person. > {'sql': u'SELECT "vortaro_car"."id", "vortaro_car"."name", > "vortaro_car"."owner_id" FROM "vortaro_car" LIMIT 21', > 'time': '0.000'}] Here nothing is found, as excepted. > This isn't making a second query to deleting the Car model, it is > depending on the database to do this. It did make a delete to the Car model, but _before_ the person was deleted. That is the correct order to delete the objects. > For comparison, here's the same on App Engine: <SNIP> > In [7]: c.owner <SNIP> > DoesNotExist: Person matching query does not exist. I believe AppEngine could have executed the above queries, there are no joins. Instead it has deleted the Person, but left the related car in the DB. - Anssi -- You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com. To unsubscribe from this group, send email to django-developers+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-developers?hl=en.