Yesterday, I created a table which doesn’t contain any custom columns, i.e. it contains only the columns “id”, “created”, and “modified”:

CREATE TABLE users (
  id INT(11) NOT NULL AUTO_INCREMENT,
  created DATETIME,
  modified DATETIME,
  PRIMARY KEY (id)
);

The corresponding model is pretty simple:

class User extends AppModel {}

Even though this is probably one if the simplest models you can have, it is not possible to save it with the save() method of the model. The method returns “success”, but no record is written to the database:

$this->User->create();
if ($this->User->save()) {
    echo 'save successful';
} else {
    echo 'save failed';
}

My second approach was to manually set the id to null. This created a new record, but it left the “created” and “modified” columns untouched:

$this->data['User']['id'] = null;
$this->User->create();
if ($this->User->save($this->data)) {
    echo ’save successful’;
} else {
    echo ’save failed’;
}

As a workaround I wrote the following method in my model:

function createUser() {
    $this->query('INSERT INTO '.$this->table.' (modified, created) VALUES (now(), now())');
    $data = $this->query('SELECT LAST_INSERT_ID() AS insertID');

    return $data[0][0]['insertID'];
}

Maybe it helps someone else until this bug gets fixed.