AlexBrand
AlexBrand

Reputation: 12399

Cakephp - save method creating record but without data

For some reason, my model's save method is creating records in the database but the fields are all empty or zeroes.

The form should allow for creating multiple records with a single form submission.

My $this->data array:

Array
(
[OfferingStudent] => Array
    (
    [0] => Array
        (
            [offering_id] => 35
            [owing] => 209.00
            [student_id] => 31
        )

)

)

Using the save method: $this->Students->OfferingsStudent->saveAll($this->data)

What could be causing this?

Upvotes: 0

Views: 610

Answers (1)

Brian Glaz
Brian Glaz

Reputation: 15676

I believe when using saveAll you don't actually include the name of the model in the array. Try changing your data to just this:

Array
(
    [0] => Array
        (
            [offering_id] => 35
            [owing] => 209.00
            [student_id] => 31
        )

)

http://book.cakephp.org/view/1031/Saving-Your-Data

from that page:

Note that we are passing $data['Article'] instead of usual $data. When saving multiple records of same model the records arrays should be just numerically indexed without the model key.

or rather, just use $this->data->OfferingStudent as the first argument to saveAll instead of just $this->data

Upvotes: 2

Related Questions