Ivan Seidel
Ivan Seidel

Reputation: 2362

Store same content "type" in one table with Mysql

i'm creating a simple forum in my database, and one of the things that a topic has is many comments.

The database structure is not the problem, i'm actualy looking for a way to use the same comments table, with blog comments. (I don't know how exacly i explain this, but i will try)

I want that the blog posts table, have many comments (ok), and that the forum topics have also many comments.

As Comments in the blog, and in topics are the same for me, would it be nice to store all of them in the same place? If yes, how can i distinguish one from other, and also 'find' them accurately?

(I would have searched google if i knew the keyword... I had this problem other times, but i solved it creating a different name for the table, but they were the same, just referencing other thing...)

I'm using CakePHP.

Ivan

Upvotes: 0

Views: 100

Answers (2)

MrSil
MrSil

Reputation: 618

Why don't use differnt index name?

For blog - blog_id

For forum - topic id

Upvotes: 0

Gianpaolo Di Nino
Gianpaolo Di Nino

Reputation: 1147

A simple way, table comments in which you store all the comments

id|text   |user_id
1 | hello |1
2 | world |2

then you reference this table from other tables you need such blog_comments:

id|discussion_id|comment_id|timestamp
1 |1234         |1         |2012-19-09 20:30:00

discussion_id is the root or forum_comments:

id| forum_id| comment_id| timestamp
1 |123444   |2          |2012-19-09 20:31:00

as well forum_id is the argument of the forum and the comment_id a reference to comments.

Upvotes: 1

Related Questions