TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 12-15-2007, 06:33 PM   #1 (permalink)
The Frequenter
Prolific Welcomer Upcoming Programmer 
 
Join Date: Sep 2007
Posts: 360
Thanks: 24
Haris is on a distinguished road
Default When a parent row is deleted..

For e.g, I have a table users linked with sessions and comments.

The comments and session has a foreign key of users.id related with comments.user and sessions.user

How would I delete the data from the child table if the data from the parent table is deleted.

In my case, how would I delete all the rows relating to user 5 in comments and sessions table when user 5 is deleted from the users table?

I am looking for a relationship method, not a query.

__________________
Necessity is the mother of invention.

My blog
Haris is offline  
Reply With Quote
Old 12-15-2007, 08:43 PM   #2 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

You'll be wanting cascading delete for that sort of stuff.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 12-30-2007, 06:19 AM   #3 (permalink)
The Wanderer
 
Join Date: Nov 2007
Posts: 9
Thanks: 0
macov is on a distinguished road
Default

The question is if you should do a cascading delete. Just think. You have a blog, users post comments to your articles, and if an user account is removed should all his/her comments be deleted? It looks quite different for a SESSIONS table.
macov is offline  
Reply With Quote
Old 12-30-2007, 01:52 PM   #4 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

I'd rather them deleted than what MySpace does and puts "Account does not exist" with an avatar of a red cross next to it. I like to put a comment to a face!

Surely there are privacy issues that arise in that when a user is removed from the system they would much prefer it if everything was removed. That's part of the argument that's on-going with Facebook at the moment - something about people not being able to remove their very last picture from their account. As well as the intrusive advertising idea.

Another issue arises however. If you were to be the nice guy and remove everything relating to that user, you will undoubtedly be left with nonsensical conversations in the blog comments.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 06:01 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design