Oops, missed out the view (note the HATBM field indexes):
<?php echo $form->create("Post", array("action"=>$this->action)) ?>
<?php echo $form->input("Post.id") ?>
<?php echo $form->input("Post.name") ?>
<?php echo $form->input("Tag.0.PostsTag.tag_id", array("options"=>
$tags))?>
<?php echo $form->input("Tag.0.PostsTag.weight")?>
<?php echo $form->input("Tag.1.PostsTag.tag_id", array("options"=>
$tags))?>
<?php echo $form->input("Tag.1.PostsTag.weight")?>
<?php echo $form->end("Submit") ?>
On Feb 16, 11:01 am, "rich...@home" <[email protected]> wrote:
> 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 [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