Re: DB relations and delete question

2008-07-03 Thread Russell Keith-Magee

On Fri, Jul 4, 2008 at 12:08 AM, Jad <[EMAIL PROTECTED]> wrote:
>
> Lets say we have Accounts that is referenced profile, group, interest
> tables.
>
> If I delete the account ID 1 would the related data to that account in
> profile, group and interest table be deleted in all cases of relation?
>  One to one, one to many, many to many? same question applies to
> update

Essentially, the question Django asks is "If I delete object A, will
that invalidate object B?". If B has a foreign key reference on A that
cannot be null, deleting A would leave B in an invalid state (B
pointing to nothing), so Django will delete B as well. If C has a
foreign Key reference on B, then the deletion of B will cascade on to
C, and so on.

OneToOne fields are just the degenerate case of Foreign Keys, so the
same rules apply.

Many to Many fields are unaffected (although any references to A
specific entry in m2m tables will be deleted).

This behaviour is the equivalent of 'ON DELETE CASCADE' at a database
level; however, SQLite (and, if I remember correctly, MySQL) doesn't
have support for ON DELETE CASCADE, so Django implements the
equivalent behaviour using DELETE calls.

Yours,
Russ Magee %-)

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: DB relations and delete question

2008-07-03 Thread Jad

I'm not asking about certain DB engine but how django would behave in
presence of foriegn key?

II will give an exampel of what arised this concern.

http://www.djangoproject.com/documentation/db-api/

One-to-many relationships
Forward
If a model has a ForeignKey, instances of that model will have access
to the related (foreign) object via a simple attribute of the model.

and in Backward
# Note that there’s no need to specify the keyword argument of the
model that defines the relationship. In the above example, we don’t
pass the parameter blog to create(). Django figures out that the new
Entry object’s blog field should be set to b.
# remove(obj1, obj2, ...): Removes the specified model objects from
the related object set.



http://www.djangoproject.com/documentation/models/many_to_one/
# If you delete a reporter, his articles will be deleted.



So finally I wonder if django behave differently if we define
ManyToManyField, one to many or one to one.

Thank you


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: DB relations and delete question

2008-07-03 Thread bbeaudreault

Wouldn't it depend on the type of DB? (mysql, postgresql,etc)? Or is
this something enforced in django regardless of db?

On Jul 3, 1:28 pm, Randy Barlow <[EMAIL PROTECTED]> wrote:
> Jad wrote:
> > Lets say we have Accounts that is referenced profile, group, interest
> > tables.
>
> > If I delete the account ID 1 would the related data to that account in
> > profile, group and interest table be deleted in all cases of relation?
> >  One to one, one to many, many to many? same question applies to
> > update
>
> My understanding is that deletion is a cascading operation, following
> all relations in the database.  So use it very carefully!
>
> --
> Randy Barlow
> Software Developer
> The American Research Institutehttp://americanri.com
> 919.228.4971
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: DB relations and delete question

2008-07-03 Thread Randy Barlow

Jad wrote:
> Lets say we have Accounts that is referenced profile, group, interest
> tables.
> 
> If I delete the account ID 1 would the related data to that account in
> profile, group and interest table be deleted in all cases of relation?
>  One to one, one to many, many to many? same question applies to
> update

My understanding is that deletion is a cascading operation, following
all relations in the database.  So use it very carefully!

-- 
Randy Barlow
Software Developer
The American Research Institute
http://americanri.com
919.228.4971

--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---