2

I'm trying to save IssueHistoryDescription, which belongsTo IssueHistory. So IssueHistory hasMany IssueHistoryDescription. This has all been set in the model.

Yet, when I save this in IssueHistory, using $IssueHistory->save($data);

(With or without a $IssueHistory->create(); before...)

Array
(
    [IssueHistory] => Array
        (
            [id] => 22
        )

    [IssueHistoryDescription] => Array
        (
            [old_description] => OLD
            [description] => NEW
        )

)

It doesn't work, nothing is saved.

When I try to use saveAssociated() I get an error:

Fatal error: Cannot use string offset as an array in /var/www/xdev/kipdomanager/cakephp/lib/Cake/Model/Model.php on line 2248

1
  • You can try cakephp saveAll() method... Commented Sep 6, 2012 at 20:18

1 Answer 1

4

You can try this:

$data = array(
    'IssueHistory' => array('id' => 2),
    'IssueHistoryDescription' => array(
        array('old_description' => 'OLD', 'description' => 'new')
    )
);

$IssueHistory->create();
$IssueHistory->saveAll( $data );
1
  • That did it. I didn't know you had to put the hasMany fields into another array. I am using saveAssociated, though, because saveAll() is apparently specifically for HABTM data. Commented Sep 6, 2012 at 20:24

Not the answer you're looking for? Browse other questions tagged or ask your own question.