Create proper global model relation properties to describe how models relate
- The Models aren't making use of any relation properties and as a result we can't make use of the full feature set available in CakePHP concerning these. This also creates the need to have these defined per request on the fly as in Model/User.php e.g. This was defined in the controller, it needs to be defined in the appropriate Model class. app/Controller/UsersController.php
public function indexall()
{
$this->User->hasMany = array(
'UserAttribute' => array(
'className' => 'UserAttribute',
'foreignKey' => 'UserID',
'associationForeignKey' => 'ID',
'conditions' => array('UserAttribute.Name' => 'User-Password'),
)
);
$this->User->recursive = 1;
//...
}
- A good way to test that your relations work would be to enable scaffolding in the AppController and seeing that the generated forms interact as expected.
Ref: