In my application there are 2 related models and Shortcut and Role, where Role has several Shortcuts, the connection between the two normally occurs, except when trying to create an input in the "save" view of the controller Shortcut to select a Role existing.
Model Shortcut
<?php
class Shortcut extends AppModel
{
public $name = 'Shortcut';
public $diplayField = 'title';
public $useTable = 'shortcuts';
public $belongsTo = array( 'Role' => array('className' => 'Role','foreignKey' => 'role_id' ) );
}
?>
Model Role
class Role extends AppModel
{
public $name ='Role';
public $useTable = 'roles';
public $displayField = 'title';
public function getAdminRole()
{
return 3;
}
public function getUserRole()
{
return 2;
}
public function getPublicRole()
{
return 1;
}
}
View / Shortcuts / Save
<?php echo $this -> Form -> create('Shortcut'); ?>
<table>
<tr>
<td>
<label>TÍTULO</label>
</td>
<td>
<?php echo $this -> Form -> input('title',array('label'=>null));?>
</td>
</tr>
<tr>
<td>
<label>LINK</label>
</td>
<td>
<?php echo $this -> Form -> input('link',array('label'=>null));?>
</td>
</tr>
<tr>
<td>
<label>PERMISSÃO</label>
</td>
<td>
<?php echo $this -> Form -> input('role_id',array('label'=>null));? >
</td>
</tr>
<tr>
<td>
<?php echo $this -> Form -> submit('Enviar',array('controller'=>'shortcuts','action'=>'save'));?>
</td>
</tr>
</table>
<?php echo $this -> Form -> end();?>