I'm using CakePHP v2.3.5. When I update the table
`users` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`email` varchar(320) NOT NULL,
`password` varchar(45) NOT NULL,
`firstname` varchar(255) DEFAULT NULL,
`lastname` varchar(255) DEFAULT NULL,
`country` varchar(255) DEFAULT 'SG',
PRIMARY KEY (`id`)
);
using $this->User->save($this->request->data)
, it always fires an insert command and throws
"Integrity constraint violation: 1062 Duplicate entry '10' for key 'PRIMARY'"
The request->data
object is:
array(
'User' => array(
'id' => '10',
'firstname' => 'Someone',
'lastname' => 'Surname',
)
)
The complete action I'm using now is:
public function addInfo() {
if ($this->request->is('post')) {
$this->User->create();
$this->User->id=(int)$this->request->data['User']['id'];
if ($this->User->save($this->request->data)) {
}
}
}
And the beforeSave function in Model is:
public function beforeSave($options = array()) {
if (isset($this->data['User']['password'])) { $this->data['User']['password'] = AuthComponent::password($this->data['User']['password']); } return true;
}
In User Object, this id=>false looked fishy to me
object(User) { displayField => 'firstname' primaryKey => 'id' useDbConfig => 'default' useTable => 'users' id => false data => array( [maximum depth reached] ) }
'id'=>10
(10 as integer) in therequest->data
array – Nunser$this->User->id = 10;
right before the save action? – Alex Stallen