Hi all,
I'm trying to associate new HABTM instances with an existing record,
and I feel like I'm making it more complicated than it needs to be. I
have a 'content' model that has a HABTM relationship with a 'tag'
model. I already know the ID of the content record, and am creating
new tags from an array. My code (in my 'content' controller) currently
looks like this:
foreach ($tags as $tag) {
$this->Content->Tag->create();
if ($this->Content->Tag->save(array('tag' => trim($tag)))) {
$tagIds[] = $this->Content->Tag->id;
}
}
$tagData['Content'] = array('id' => $this->data['Content']['id']);
$tagData['Tag'] = $tagIds;
$this->Content->save($tagData);
Is this correct? I feel like I should be able to do all of the above
in one hit, using saveAll, but nothing I try works - am I missing
something?
Thanks in advance,
Toby
--
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=.