Having recently been building an import tool for our latest site at work, I was reminded of a very important thing to remember when creating rows in CakePHP.

If you create more than one row in a loop, you must call create() before you call save().

foreach ($rows as $row) {
    $this->Model->create();
    $this->Model->save($row);
}

The create function will reset the model internals associated with saving rows. If you don’t call it, your subsequent calls to save() will merely update the first one added.

It’s important to note that create() doesn’t actually create the row, it just tells Cake that we’re about to create one.