Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > Database Server Software > PostgreSQL > threaded forum/comment system

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-10-07, 20:08
Force Flow Force Flow is offline
Registered User
 
Join Date: May 2005
Posts: 4
threaded forum/comment system

I'm trying to figure out what the best solution would be for making a threaded comment/forum system. I'm also looking to apply the same technique to categories and subcategories on a website.

I've come across this, which looks fairly promising: http://www.sqlteam.com/article/sql-f...cussion-forums

The only thing is...what happens when you want to delete a parent, or move a child to another parent? (after all, I don't want orphans here ). It seems like there would be some fairly complex steps that would need to be taken.

Any suggestions? I'm trying to keep most of this code towards the database side of things, rather than trying to wrestle with it with a server-side language.

Thanks
Reply With Quote
  #2 (permalink)  
Old 12-13-07, 02:08
loquin loquin is offline
Super Moderator
 
Join Date: Jun 2004
Location: Arizona, USA
Posts: 1,359
Well.....

If you enforce referential integrity in the database, and you define the integrity constraints with ON DELETE CASCADE ,deletions should take place automatically.

On the other hand, moving a child to another parent would require no activity on any of the children of the affected record, as THEIR parent wouldn't change. (child records reference the parents, and not the other way around)

I took a quick look in the author's table layouts; he likes to pre-sort the records in the table (by applying a default sort order to the records), which would lead to update issues.

In the case of a delete, it wouldn't matter a bit, as you would just removing numbers out of the middle of a sorted list; the remaining records order wouldn't change at all. (Yes, there WOULD be a gap, but it wouldn't affect the order.)

In the case of a move, it would affect things at the new parent's thread. (In the old parent's thread, it would be like a delete - no update required...)

You would want to kick off a process, probably an update trigger, to re-sort the target thread when you insert a new child. Since you would have to have a procedure to do this when you append a new post, just call the same procedure when you move a thread to another parent. (Remember, the only records that would need to be updated are those that fall "below" the new post/thread)

Here's another possibility. Why not add a flag field used (or referenced by) the the top-level post in a thread. Whenever you add or move a post/thread to a parent, set the flag. When a user tries to view the thread, if the flag is set, trigger a sort, which resets the flag when it's done. That way, if no-one is looking at the thread, nothing needs to be sorted. You could always run a batch process periodically to re-sort the threads that need it.
__________________
Lou
使大吃一惊
"Lisa, in this house, we obey the laws of thermodynamics!" - Homer Simpson
"I have my standards. They may be low, but I have them!" - Bette Middler
"It's a book about a Spanish guy named Manual. You should read it." - Dilbert


Last edited by loquin : 12-13-07 at 02:30.
Reply With Quote
Reply


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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On