This syntax is wrong:
echo $this->Form->input('User');
You don't have a field named "User" in your Profile
model. This should be:
echo $this->Form->input('user_id');
Question
I have a table profiles
and a table users
, and profiles
has a belongsTo
relationship with users
. On my profiles/edit
view, I have a dropdown of existing users
to select from.
However, the users.id
is not being saved in profiles.user_id
, as I would expect.
ProfilesController.php -> edit:
$this->set('users', $this->Profile->User->find('list'));
And in View -> Profiles -> edit.ctp
echo $this->Form->input('User');
Running debug($this->request);
in the controller shows that the proper values are being sent back to the controller. The save action looks like:
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.'));
}
}
In the returned data:
data => array(
'Profile' => array(
'User' => '3',
...
Solution
This syntax is wrong:
echo $this->Form->input('User');
You don't have a field named "User" in your Profile
model. This should be:
echo $this->Form->input('user_id');