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