Sorry I got it wrong in hurry :) Can you please check out the following schema again?
tags: id, name entity_types: id, name [(0, Posts), (1, Teachers), (2, Books)] posts: id, name teachers: id, name books: id, name entities_tags: id, entity_id, entity_type_id, tag_id With this schema please have your models like the following, *Post Model* <?php class Post extends AppModel { var $name = 'Post'; var $hasAndBelongsToMany = array( 'Tag' => array ( 'className' => 'Tag', 'joinTable' => 'entities_tags', 'foreignKey' => 'entity_id', 'associationForeignKey' => 'tag_id', 'conditions' => 'entity_type_id = 0' ) ); } ?> *Teacher Model* <?php class Teacher extends AppModel { var $name = 'Teacher'; var $hasAndBelongsToMany = array( 'Tag' => array ( 'className' => 'Tag', 'joinTable' => 'entities_tags', 'foreignKey' => 'entity_id', 'associationForeignKey' => 'tag_id', 'conditions' => 'entity_type_id = 1' ) ); } ?> *Book Model* <?php class Book extends AppModel { var $name = 'Book'; var $hasAndBelongsToMany = array( 'Tag' => array ( 'className' => 'Tag', 'joinTable' => 'entities_tags', 'foreignKey' => 'entity_id', 'associationForeignKey' => 'tag_id', 'conditions' => 'entity_type_id = 2' ) ); } ?> *Tag Model* <?php class Tag extends AppModel { var $name = 'Tag'; } ?> I could not try out this code. But I hope it will work and serve the purpose :) Thanks. On Sun, Nov 2, 2008 at 5:36 PM, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > This does not serve the purpose because tagging needs to be > implemented on all the 3 types of entities : Posts, Teachers and > Books . > > On Nov 1, 11:15 pm, Anupom <[EMAIL PROTECTED]> wrote: > > Please find my suggested db design below, > > > > tags: id, name > > types: id, name > > posts: id, name > > teachers: id, name > > books: id, name, type_id > > books_tags: id, book_id, tag_id > > All ids are auto increment & primary fields. > > > > So if, the book with (id, name, type_id) = (6, 'Bookname', 2) has two > tags > > with (id, name) = (11, 'Chemistry') & (23, 'Grade A'), then the entry in > the > > books_tags(book_id, tag_id) table for this will be - (6, 11) & (6, 23) . > > Also read this page from the dochttp:// > book.cakephp.org/view/24/Model-and-Database-Conventions > > > > -- > > Anupom Syamhttp://syamantics.com/ > > > > On Sat, Nov 1, 2008 at 8:42 PM, [EMAIL PROTECTED] <[EMAIL PROTECTED]> > wrote: > > > > > Hi All, > > > > > I am trying to build a tagging feature in my site which is a community > > > site for a school. > > > > > In my site, I have various entity types like : Blog Post, Teacher, > > > Book . > > > > > Every entry for these entities will have tags associated with it . So, > > > a tag may belong to one or more items of different entities. > > > > > In a normal core PHP project, I would have designed tables for this in > > > the following manner :- > > > > > 1) tags : tag_id, tag_name . > > > 2) entity_types : entity_type_id, entity_type_name . [(0, Posts), > > > (1, Teachers), (2, Books)] > > > 3) posts : post_id, post_name . > > > 4) teachers : teacher_id, teacher_name . > > > 5) books : book_id, book_name > > > 6) entities_tags : tag_id, entity_type_id, entity_id . > > > > > So, if a book (entity_type_id = 2) with book_id = 6 has 2 tags > > > (tag_id, tag_name) : (11, 'Chemistry') & (23, 'Grade A') , then the > > > entry in entities_tags for this will be : (11, 2, 6) & (23, 2, 6) . > > > > > I am using CakePHP for my project and I am not able to design the > > > tables in CakePHP for this Tagging Feature. > > > > > It would be great if people could come up with their suggestions. > > > > > Thanks a lot !! > > > -- Anupom Syam http://syamantics.com/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---