This is a reoccurring question, brought about from not reading the
official documentation. Simply replace
$tagData['Tag'] = $tagIds;
with
$tagData['Tag']['Tag'] = $tagIds;
and if your models are associated correctly it should save.
On Nov 19, 1:45 am, toby1kenobi <[email protected]> wrote:
> 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=.