On Wednesday 03 February 2010 20:21:49 kanu wrote:

> My Ticket http://code.djangoproject.com/ticket/12760 Titled :
>  "related models with Foreignkey.null=True must not get deleted on
>  delete of their relation" was marked as dublicate today.
> 
> I don't aggree that this is a dublicate. i filed this as a bug not
>  a feature request.

This 'bug' has been reported various times, and it depends on your 
point of view whether it is a bug or not.  There are certainly cases 
where the opposite would be a bug.  Consider, for instance, this 
model:

class Employee(Model):
   boss = ForeignKey('self', null=True)

The semantics of this model might include the idea that employees with 
boss == NULL are directors.  Now, if we delete employee e1 who happens 
to be the boss of employee e2, and just null out e2.boss, we have 
promoted e2 to being a director, which is not intended.

So this is a feature request, and on your bug, I linked to the most 
recent, open bug covering it.

> I really think that it was intendet to not delete those relations.
> e.g. the comments in CollectedObjects.add say :
> # Nullable relationships can be ignored -- they are nulled out
>  before # deleting, and therefore do not affect the order in which
>  objects # have to be deleted.
> 
> Even if it is not a bug the code appears a little confusing.
> Why is a relation updated and afterwards deleted ?

Karen is right, it allows mutually related data to be deleted without 
causing an integrity error in the absence of transactions:

class A(Model):
   b = ForeignKey(B)

class B(Model):
   a = ForeignKey(A, null=True)

By noticing the null=True, we can null out B.a, then delete the A 
object, then the B object, all without requiring a transaction.  
CollectedObjects uses this logic to decide that the correct order of 
deletion is A,B.  Another part of the code actually does the nulling 
out and deleting.

Hope that explains it, sorry if the message was rather brief, but this 
has come up several times before and we can't explain it every time.

Cheers, 

Luke

-- 
"Where a person wishes to attract, they should always be ignorant." 
(Jane Austen)

Luke Plant || http://lukeplant.me.uk/

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" 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-developers?hl=en.

Reply via email to