Many thanks for the reply. I've successfully managed to get my HABTM
models saving its extra field.

Just for the record, if anyone else is looking for the answer:

class Post extends AppModel {

        var $hasAndBelongsToMany = array(
                "Tag"=>array(
                        "with"=>"PostsTag"
                )
        );

}

class Tag extends AppModel {

        var $hasAndBelongsToMany = array(
                "Post"=>array(
                        "with"=>"PostsTag"
                )
        );

}

class PostsTag extends AppModel {

        var $belongsTo = array(
                "Post",
                "Tag"
        );

}

PostsController:

        function edit($id) {

                if (!empty($this->data)) {

                        
$this->Post->bindModel(array('hasMany'=>array('PostsTag')));

                        if ($this->Post->saveAll($this->data, 
array('validate'=>'first')))
{

                                $this->Session->setFlash("Saved");

                        }
                        else {

                                $this->Session->setFlash("Error");

                        }
                }
                else {

                        $this->data = $this->Post->read(null, $id);

                }

                $this->_populateLookups();

                $this->render("form");

        }

So, in a nutshell, create your HABTM using $hasAndBelongsToMany and
force the join before the save with

$this->Post->bindModel(array('hasMany'=>array('PostsTag')));

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

Reply via email to