Containable is not behaving as I expect in CakePHP 2.1.2 in the following code:
class ReportCard extends AppModel {
....
// debug shows expected results
public function test1(){
$this->Behaviors->attach('Containable');
$params = array(
'conditions' => array('ReportCard.id' => 1),
'contain' => array(
'ReportCardGradingPeriodCollection' => array(
'GradingPeriodCollection')));
debug($this->find('first', $params));
$this->Behaviors->detach('Containable');
}
// Unexpected: debug shows same array as test1
public function test2(){
$this->Behaviors->attach('Containable');
$params = array(
'conditions' => array('ReportCard.id' => 1),
'contain' => array(
'ReportCardGradingPeriodCollection' => array(
'GradingPeriodCollection' => array(
'GradingPeriodCollectionDetail' => array(
'GradingPeriod')))));
debug($this->find('first', $params));
$this->Behaviors->detach('Containable');
}
}
I get unexpected results when calling the functions from the controller. test1()
shows the expected array. test2()
shows the same array from test1
. If I run test2()
then test1()
I get expected results (large array, then small array).
class ReportCardsController extends AppController {
....
public function test(){
$this->ReportCard->test1();
$this->ReportCard->test2();
}
}
I have tried using actAs
in the model instead of dynamically loading the behavior in each function, but that did not help.
I apologize if I'm missing something simple. Thanks in advance!