That's not the way I've got my db set up. Mine looks like this:

id|name|parent
1|Books|0
2|Sci/Fi|1
3|Starship Troopers|2
4|Friday|2

So if I deleted Sci/Fi, records 3 and 4 would be orphaned.

I'm using mySQL by the way (if it matters).


<!----------------//------
andy matthews
web developer
ICGLink, Inc.
[EMAIL PROTECTED]
615.370.1530 x737
--------------//--------->

-----Original Message-----
From: Barney Boisvert [mailto:[EMAIL PROTECTED]
Sent: Tuesday, January 31, 2006 5:31 PM
To: CF-Talk
Subject: Re: Nested Set Model


Really, there's nothing to change.  No triggers, procs, magic, or
anything.  Delete a record, and nothing in the tree gets orphaned. 
Say you've got a table like this:

Name Left Right
food 1 8
fruit 2 7
apple 3 4
banana 5 6

That is, food has a child fruit, which has two children apple and
banana.  Now delete fruit.  Apple and banana are still inside the food
set, without changing anything.

Say you have the same tree, but with an adjacency list:

name parent
food NULL
fruit food
apple fruit
banana fruit

Now if you delete fruit, apple and banana are suddenly parentless, and
they have no connection to food at all.  Or they might have been
inadvertantly deleted as well, if you've got a FOREIGN KEY with
CASCADE DELETE set on the parent field.

cheers,
barneyb


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Message: http://www.houseoffusion.com/lists.cfm/link=i:4:230937
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to