Hi,
I want to save an extra field in a HABTM Join table.
1) tags : id, tag .
2) blogs : id, title, body
3) entity_tags : id, entity_id, entity_type_id, tag_id .
Blog Model :
<?php
class Blog extends AppModel {
var $name = 'Blog';
var $actsAs = array ('Tag', 'Containable');
var $hasAndBelongsToMany = array(
'Tag' => array('className' => 'Tag',
'joinTable' => 'entity_tags',
'foreignKey' => 'entity_id',
'associationForeignKey' => 'tag_id',
'unique' => true,
'conditions' => 'EntityTag.entity_type_id = 1',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'finderQuery' => '',
'deleteQuery' => '',
'insertQuery' => ''
)
);
?>
Tag Model :
<?php
class Tag extends AppModel {
var $name = 'Tag';
}
?>
I am calling $this->Blog->save($this->data) in blogs_controller for
saving tags and blog.
3 things are happening here :
1) Tags are getting saved into tags table using tag behavior and also
setting $model->data['Tag']['Tag'] = $tags;
function beforeSave(&$model) {
---------------Tag Behaviour---------------------
foreach ($tagList as $tag) {
$Tag->save(array($this->settings[$model->name]['tag_label'] =>
$temp));
// Store newly added tag's id in array
$tags[] = sprintf($Tag->getLastInsertID());
}
// Store tags list then unset not needed data and return true
$model->data['Tag']['Tag'] = $tags;
return true;
}
2) Blog-Posts (blog title, blog body) are getting saved into blogs
table
3) id(auto_increment), entity_id(blog_id), tag_id is getting saved
into entity_tags table but entity_type_id is not getting saved.
I don't know where and what should I write for saving entity_type_id
into entity_tags table.
I also wrote a similar problem some days back but did not get a
satisfactory solution...
Please help me to come out of this problem
Thanks
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---