I've searched around looking for HABTM saving solutions, but for the
last few days I can't seem to get this working...

For my blog, I already had "Posts" and "Comments" set up with
controller logic and model associations for "Posts has many comments".
I wanted to make it so one "comments" table could store data for
multiple sections (like comments for videos and pictures, etc) and so I
needed a HABTM relationship...

Now i have the following tables: posts, comments, comments_posts. I
changed the Post and Comment models around for the HABTM association,
translated the foreign keys to the joining table, and to my surprise,
my blog still retrieved all the posts and their associated comments
just fine. However, my comment form is now broke :(

I wrote a method in my Comment model that retrieves the last used ID
and I increment that value and add it to
$this->data['Comment']['Comment'] when the form posts (as the manual
says to do) but I still had no results. The comments themselves are
being inserted into the "comments" table, but my nothing is being
inserted into the "comments_posts" table...

I found this page,
http://groups.google.com/group/cake-php/browse_thread/thread/602603f175ccacb8/c264a4e73c5d5b21?lnk=gst&q=HABTM+save&rnum=2#c264a4e73c5d5b21
And tried the $this->data['Comment']['Comment']['id'] as suggested in
the thread, but I still get the same results.

Here's my "comments" controller's "add" action for creating a new
comment:

function add() {
        $this->layout = 'ajax';

        $this->data['Comment']['Comment']['id'] =
($this->Comment->getLastCommentId() + 1);
        $this->Comment->save($this->data);

        $this->set('comment', $comment);
}

And the queries that cakePHP runs when the comment form is used:

6 queries took 0 ms Nr  Query   Error   Affected        Num. rows       Took 
(ms)
1       DESC `comments`         4       4       0
2       DESC `users`            7       7       0
3       DESC `posts`            4       4       0
4       SELECT id FROM Comment ORDER BY id DESC LIMIT 1 1146: Table 'Comment'
doesn't exist                   0
5       SELECT id FROM Comment ORDER BY id DESC LIMIT 1 1146: Table 'Comment'
doesn't exist                   0
6       INSERT INTO `comments` (`body`,`user_id`,`created`) VALUES
('test','1','2006-07-26 15:45:25')              1               0

I'm not sure why cake is trying to call a non-existant table. I think
that might be a hint, but I have no idea what it might mean.

If you're still reading this, I'm sorry for the long post, but I like
to be detailed :-P

Any help would be much appreciated! Thanks :)


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~----------~----~----~----~------~----~------~--~---

Reply via email to