Containable with mixed arguments, the CakePHP Beauty!

Here’s an example of CakePHP Containable behaviour. Although, it was not a very complex find call but the beauty of the containable is this that you can fetch records using “tricky ways” which normally may not be possible with straight associations find calls.

For example look at the following code at the line 6. I could call the association of model Control which is User model and I could have model name and mixed fields in the same array of argument. Then I could supply the field names of the User model in the same array along with id and control_name which are related to Control model.

[php collapse=”false”]
$options = array(
‘conditions’ => array(‘ControlsAssignee.’ . $this->Control->primaryKey => $id),
‘Control’=>array(‘User’, ‘’, ‘User.full_name’, ‘id’, ‘control_name’),

Leave a Reply