Hello all,
I've decided to try the example from documentation explaining HABTM
association.
I had setup posts, tags and posts_tags and proper association.
But documentation doesn't explain the main thing: how to save NEW post
with the NEW tags, not listed in the multiple select, but in the input
separated by comma, for example?
What I did:
in the Post model:
function beforeSave()
{
$this->data['Tag']['Tag'] = explode(",", $this->data['Tag']
['Tag']); // making array of tags from input field
$this->data['Post']['user_id'] =$this->user['id']; // current
user
id
return true;
}
Then, after saveing Post Cake produces following queries:
7 INSERT INTO `posts`
(`category_id`,`title`,`content`,`user_id`,`created`,`modified`)
VALUES ('4','title3','text3','4','2007-01-30 14:23:31','2007-01-30
14:23:31') 1 1
8 DELETE FROM `posts_tags` WHERE post_id = '6' 0 0
9 INSERT INTO `posts_tags` (post_id,tag_id) VALUES ('6','tag1') 1 0
10 INSERT INTO `posts_tags` (post_id,tag_id) VALUES ('6','tag2') 1062:
Duplicate entry '6-0' for key 1 0
11 INSERT INTO `posts_tags` (post_id,tag_id) VALUES ('6','tag3') 1062:
Duplicate entry '6-0' for key 1 1
Queries 9,10,11 are completely wrong. It must save first tags into
Tags, and THEN IDs into Posts_Tags. But it trying to save tags into
posts_tags :-/ (tag1,tag2,tag3 - are tags, not ids)
Of course I can do this stuff without associations using only query()
function, but I want to do it Cake-way.
Please help!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" 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
-~----------~----~----~----~------~----~------~--~---