Re: Building Tagging feature in my site
Good post..I have same problem...It's working but in my case entity_type_id is not saving in entities_tags tabel... Currently I am using it only in *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' ) ); } ? here 'entity_type_id is always saving 0 but it must be save 1 in database... Please tell me where should I define 'entity_type_id = 1 other than relation ship so that it can be save. On Nov 3, 2:59 pm, Marcus Silva [EMAIL PROTECTED] wrote: Hi, If i did understand what you are trying to achive you could design your tag relationship in the following way: Tables --- Tags id name model created updated more if needed etc... then you would have a linking table which would link tags to its repective associated model. Example: model_tags //name it as you like foreign_id //id of associated model tag_id Lets say thatmyusers uses tags etc... User -- model var $hasAndbelongsToMany = array( 'Tag' = array( 'className' = 'Tag', 'joinTable' = 'model_tags', 'foreignKey' = 'foreign_id', 'associationForeignKey' = 'tag_id', 'unique' = true, 'conditions' = array(Tag.model' = 'User'), // Tag.model = Associated model class name 'fields' = '', 'order' = '', 'limit' = 5, 'offset' = '', 'finderQuery' = '', 'deleteQuery' = '', 'insertQuery' = '' ) ); In the tag model you could do the same thing. I know that it works because I used it before ... Hope it helps you out. Cheers On Nov 1, 2:42 pm, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Hi All, I am trying to build ataggingfeatureinmysitewhich is a community sitefor a school. Inmysite, I have various entity types like : Blog Post, Teacher, Book . Every entry for these entities will have tags associated with it . So, atagmay 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 formyproject and I am not able to design the tables in CakePHP for thisTaggingFeature. It would be great if people could come up with their suggestions. Thanks a lot !!- Hide quoted text - - Show quoted text - --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Building Tagging feature in my site
Hi, If i did understand what you are trying to achive you could design your tag relationship in the following way: Tables --- Tags id name model created updated more if needed etc... then you would have a linking table which would link tags to its repective associated model. Example: model_tags //name it as you like foreign_id //id of associated model tag_id Lets say that my users uses tags etc... User -- model var $hasAndbelongsToMany = array( 'Tag' = array( 'className' = 'Tag', 'joinTable' = 'model_tags', 'foreignKey' = 'foreign_id', 'associationForeignKey' = 'tag_id', 'unique' = true, 'conditions' = array(Tag.model' = 'User'), // Tag.model = Associated model class name 'fields' = '', 'order' = '', 'limit' = 5, 'offset' = '', 'finderQuery' = '', 'deleteQuery' = '', 'insertQuery' = '' ) ); In the tag model you could do the same thing. I know that it works because I used it before ... Hope it helps you out. Cheers On Nov 1, 2: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, atagmay 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 !! --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Building Tagging feature in my site
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 !! --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---
Re: Building Tagging feature in my site
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 -~--~~~~--~~--~--~---
Re: Building Tagging feature in my site
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 doc http://book.cakephp.org/view/24/Model-and-Database-Conventions -- Anupom Syam http://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 !! --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---