0
我想在CakePHP中將密碼更新爲兩個不同的模型/表。我可以在父模型中更新它,但不是第二個模型。CakePHP:需要幫助使用saveField來更新belongsTo模型中的字段
Models:
Users (hasOne GameProfile) PK=id
Gameprofiles (belongsTo User) FK=user_id
這是我在users_controller.php中功能的精簡版:
function updatepass() {
if (!empty($this->data)) {
$this->User->id = $this->Auth->user('id');
$this->User->saveField('sha1password', $this->Auth->password($this->data['User']['newpass']));
$this->User->Gameprofile->saveField('plainpassword', $this->data['User']['newpass']);
}
}
當我執行的功能,用戶表被更新的罰款。但是gameprofile表沒有被更新,而是Cake做了一個插入。
SQL Query Log:
1195 Query UPDATE `users` SET `sha1password` = 'e9443e9f5e1a07832aad1b2f84de1a666daf89b5' WHERE `users`.`id` = 30
1195 Query INSERT INTO `gameprofiles` (`plainpassword`) VALUES ('abc')
有沒有辦法讓CakePHP在帶有belongsTo屬性的模型上使用saveField進行更新?
我已經嘗試了各種方法來執行第二個saveField之前引用user_id,但似乎無法找到勝利的組合。
任何幫助,非常感謝!