Skip to content

Commit

Permalink
Suppose you have a component that 'listen' for some named param and i…
Browse files Browse the repository at this point in the history
…f received you need to add a binding to the next model find call, through containable, and later, in the controller you also need to do other bindings to the same next model find call, but respecting the previous component binding. As contain() have multiple parameters (func_get_args()) we need to create other method, i think this one can be good.

Hope it helps. Please review the documentation because my english it's not soo good.
  • Loading branch information
adael committed Jun 3, 2011
1 parent 8671aa3 commit 92f0869
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions cake/libs/model/behaviors/containable.php
Expand Up @@ -252,6 +252,24 @@ function contain(&$Model) {
$this->runtime[$Model->alias]['contain'] = $contain;
}

/**
* Add the specified relations to the next find call.
* Unbinds all relations from a model except the specified ones. Calling this function without
* parameters unbinds all related models.
*
* @param object $Model Model on which binding restriction is being applied
* @return void
* @access public
*/
function containAdd(&$Model) {
$args = func_get_args();
$contain = call_user_func_array('am', array_slice($args, 1));
if(!isset($this->runtime[$Model->alias]['contain']) || !is_array($this->runtime[$Model->alias]['contain'])){
$this->runtime[$Model->alias]['contain'] = array();
}
$this->runtime[$Model->alias]['contain'] += $contain;
}

/**
* Permanently restore the original binding settings of given model, useful
* for restoring the bindings after using 'reset' => false as part of the
Expand Down

0 comments on commit 92f0869

Please sign in to comment.