2
我有一個表profiles
和一個表users
,profiles
與users
有belongsTo
關係。在我的profiles/edit
視圖中,我有一個現有users
的下拉列表供您選擇。CakePHP foreignKey未保存在belongsTo關係
但是,users.id
未被保存在profiles.user_id
中,正如我所預料的那樣。
ProfilesController.php - >編輯:
$this->set('users', $this->Profile->User->find('list'));
而且在查看 - >概況 - > edit.ctp
echo $this->Form->input('User');
控制器運行debug($this->request);
表明,正確的價值觀正在被送回到控制器。保存操作是這樣的:
if ($this->request->is('post') || $this->request->is('put')) {
if ($this->Profile->save($this->request->data)) {
$this->Session->setFlash(__('The profile has been saved'));
} else {
$this->Session->setFlash(__('The profile could not be saved. Please, try again.'));
}
}
在返回的數據:
data => array(
'Profile' => array(
'User' => '3',
...
在您的代碼的這部分沒有看到問題。如果啓用了調試,您是否檢查過SQL語句? – thaJeztah 2013-03-17 21:58:12
@thaJeztah調試中的查詢報告不顯示正在保存的user_id。 – 2013-03-17 22:00:06
但它作爲Profile => user_id存在於請求數據中?奇怪的。 – thaJeztah 2013-03-17 22:04:56