Try directly $this->Tag->save($this->data); Of course you have to
specify in the header $uses = array(...'Tag');

On Sep 11, 9:08 pm, Dave <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I'm trying to do a HABTM insert using the 1.2 codebase (the current
> one on the homepage), and am having trouble. I have images, tags and
> images_tags tables, along with Image & Tag models and an
> ImageController
>
> <?php
> class Image extends AppModel {
>         var $name = 'Image';
>         var $table = 'images';
>         var $transactional = true;
>         var $hasAndBelongsToMany = array( 'Tag'    =>
>                                    array( 'className'   =>  'Tag',
>                                           'joinTable'   =>
> 'images_tags',
>                                           'foreignKey'  =>
> 'image_id',
>                                           'associationForeignKey'
> =>  'tag_id',
>                                           'conditions'  =>  '',
>                                           'order'       =>  '',
>                                           'limit'       =>  '',
>                                           'uniq'        =>  true,
>                                           'finderQuery' =>  '',
>                                           'deleteQuery' =>  ''));
>
> }
>
> ?>
>
> <?php
> class ImageController extends AppController
> {
>             ...
>             $this->Image->save($this->data);
>
>             $image_id = $this->Image->getLastInsertId();
>
>             $this->data['Tag']['image_id'] = $image_id;
>
>             $this->Image->Tag->save($this->data);
>
> }
>
> ?>
>
> The Image data saves correctly to the images table, but the $this->Image->Tag 
> returns a:
>
> Notice (8): Undefined property:  Image::$Tag [CORE/app/controllers/
> images_controller.php, line 62]
> ImagesController::upload() - CORE/app/controllers/
> images_controller.php, line 62
> Dispatcher::_invoke() - CORE/cake/dispatcher.php, line 353
> Dispatcher::dispatch() - CORE/cake/dispatcher.php, line 333
> [main] - CORE/app/webroot/index.php, line 83
>
> Fatal error: Call to a member function save() on a non-object
>
> Why isn't the Tag reference being initialised correctly in the Image
> model?
>
> Thanks in advance,
> Dave :)


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to