Monday, December 1, 2008

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 <marcuslighten...@gmail.com> 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, "dmo...@gmail.com" <dmo...@gmail.com> 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 cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: