John,

Thank you. I have taken up your advice and chosen to override the
delete method of people.

regards
suresh.

On Sep 2, 2:38 am, john <[EMAIL PROTECTED]> wrote:
> > advisor.delete() I expect should just delete the advisor object and
> > change p2.advisor and p4.advisor to None but advisor.delete() deletes
> > p2 and p4.
>
> This is the expected behavior, and it's behavior that's required to
> maintain referential integrity in the database. The docs mention it 
> athttp://www.djangoproject.com/documentation/db-api/#deleting-objects:
> "When Django deletes an object, it emulates the behavior of the SQL
> constraint ON DELETE CASCADE - in other words, any objects which had
> foreign keys pointing at the object to be deleted will be deleted
> along with it."
>
> > Is there no way to have an optional relationship to a
> > foreignobject. Ofcourse I can find all related objects for advisor,
> > disconnect them from advisor and then delete the advisor.
>
> This is exactly what you'll have to do. Maybe something like this
> (untested):
>
> for p in Person.objects.filter(advisor=advisor):
>     p.advisor = None
>     p.save()
> advisor.delete()
>
> You could also override Person's delete() method to make this the
> default behavior.


--~--~---------~--~----~------------~-------~--~----~
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