1

Im trying to do a hasmany saveall() but it does not work.

I have a Model Carmodel hasMany CarmodelsImage When i try to save, the array passed is:

[CarmodelsImage] => Array
    (
        [0] => Array
            (
                [name] => teste
                [carmodel_id] => 1
            )
    )

In the controller i have $this->Carmodel->saveAll($this->request->data) but it does not work.

I need some help.

I know this question was already posted but I read every answers and it not work.

Thanks

1
  • Can you clean up the formatting? What exactly happens? Throws an error? Returns false? What are the full contents of $this->request->data?
    – tigrang
    Commented May 15, 2012 at 2:15

1 Answer 1

4

Your requested data needs to be an array like in the following code:

Array
(
   [Carmodel] => Array
                 (
                       //Carmodel fields here
                 )
   [CarmodelsImage] => Array
                      (
                       [0] => Array
                             (
                               [name] => teste
                               [carmodel_id] => 1
                             )

                       [1] => Array
                             (
                               [name] => abc
                               [carmodel_id] => 2
                             )
                       ..........
                     )
)

$this->Carmodel->saveAll($this->request->data, array('deep' => true));

You have to use 'deep' => true option with saveAll() method while saving associated models details.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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