0

I'm working on a blog system (cliche I know, but it's a class assignment), and I want to be able to attach tags to my posts. I have a tags table and a posts table and their fields look like this:

|  p_id |  c_id  |  u_id  |    title    |    body    |    published      |
--------------------------------------------------------------------------
|   1   |   1    |    1   | first post  |lorem ipsum |2012-01-27 18:37:47|


| t_id |    name    |     slug    |
-----------------------------------
|  1   |programming | programming |

At first I thought I could just add a new field in the posts table and have a foreign key reference to each tag, and that would work if there was one tag per post, but how do I reference more than one tag?

The only thing I can think of is have another table called post_tags or something, and then reference them through that table. Is there a better way? Thanks.

James Dawson
  • 5,309
  • 20
  • 72
  • 126

2 Answers2

1

it's a basic one-to-many table model. So what your doing another table post_tags is best way.

So go with it.

1

Yes the post_tags table idea is good. It can have two columns t_id and p_id both foreign keys pointing to tags and posts respectively

Aditya Naidu
  • 1,362
  • 9
  • 12