I did a little research on tag clouds, and I ended up choosing a schema similar to the Wordpress one seen in this page: http://www.pui.ch/phred/archives/2005/04/tags-database-schemas.html
Currently, the tables that I have created is: Posts
, PostsTagMaps
, PostsTags
1) Would I need to create a table for PostsTagMaps
even if I don't plan on using a controller?
2) A Post
hasMany PostTagMaps
. I'm not sure where should I be defining this relationship. I think it should be the Post
model, but then I would have to join the PostsTags
table to PostTagsMaps
then join it to Posts
, so I wanted to ask for some advice.
The easy solution is to follow Cake conventions (which will look very similar to the solution you linked to). You'll have three tables:
posts
, tags
, posts_tags
Then your Post
model HABTM Tag
model. The join table will automatically be used by Cake to save and retrieve the information. Check the book for more information on setting up your schema.
Cake is flexible enough where you can do it however you want, but if it's a basic sort of posts-tags relationship, the convention method is the way to go.
If you want to use a custom model/table like PostsTagMaps
, then do this by using the 'with' key in your HABTM relationship definition. The 'with' key tells Cake to use a specific model (and therefore a specific table) instead of an automatically generated version. In this case, your tag model sounds like it's PostsTags
and your HABTM table is PostsTagMaps
, so the 'with' key on Post
HABTM PostsTag
would be PostsTagMap
.