In a StackOverflow clone, what relationship should a Comments table have to Questions and Answers?

前端 未结 6 1957
盖世英雄少女心
盖世英雄少女心 2020-11-30 06:14

In an application similar to StackOverflow that I am building, I am trying to decide what relationship my Questions, Answers and Comments

6条回答
  •  执笔经年
    2020-11-30 06:42

    In the social networks that I build I do something a bit different. If you think about it a comment could be attached to just about any Entity in a site. This could be a blog post, a forum thread or post, an article, someones picture, a persons profile, a vendor of a service, etc. For this reason I create a SystemObjects table which holds the object type (table reference). For the most part I create records for the Entities of my system that will accept comments...but these map directly to my tables. The SystemObjects table houses the SystemObjectID, and a friendly name for future reference (a lookup table).

    With this in place I then create a Comments table which has the SystemObjectID reference to tell me what table to go look in. Then I also house the SystemObjectRecordID which tells me which PK of the referenced table I am interested in (along with all the standard comment data).

    I use this notion of the SystemObject table for many other generic far reaching concepts in my sites. Think about Tags, Ratings, Comments, and any other dangling fruit that might be attached across your site and aggregated up for quick use.

    Read more about this in my book ASP.NET 3.5 Social Networking.

提交回复
热议问题