Yii Lazy-Loading Even Though "with"-Parameter Specified

Each time I fetch a list of products (Events), even though i specify ‘with’ => ‘details’ in the criteria, it still loads the details lazily, which is a kind of problem when you list them 30 on a page…

I’ve found the trace is from $dataProvider->getData(); which then goes on to Event->behaviors() where it loads details.

In my controller I have this:


		

$dataProvider = new CActiveDataProvider('Event');

$dataProvider->model->setScenario('search');

$dataProvider->setCriteria($this->filter->genCriteria());

		

$events = $dataProvider->getData();	



The with in genCriteria is specified like this:




$Criteria->with = array('details', 'votes', 'upvotes', 'details.locationM', 'details.category', 'nbrOfGuests');



When behaviors() is run, i have found that $this->getScenario() returns "update", which in turn triggers isset($this->details), which triggers the lazy loading of the details.




public function behaviors(){

  if(

    in_array($this->getScenario(), array('update', 'create', 'approveDetails')) 

    && isset($this->details)

    ) {

    return array(

      'sluggable' => array(

        'class'=>'ext.SluggableBehavior',

        'columns' => array('details.name'),

        'unique' => true'

        'update' => true,

      )

    );

  } else {

    return array();

  }

}



The behaviors() function looks like that because I need to update the Events from time to time, but when I do I don’t want to update the slug each and every time. Therefore the scenario is update-noslug if I’m updating without updating slug and yeah you get the point. Not really important.

Does someone know a solution for this? There’s multiple levels of weird happening:

  • When initialized, the scenario for Event is "update"

  • Event though i load details eagerly, when isset($this->details) is called, it loads the details in once more, lazily.

I have checked and the number of times .details is loaded is exactly the same as the number of events listed.

Thanks in advance!

bump since i fell off the frontpage without a single reply (and because i erroneously posted on a sunday when noone works)

Trying adding this after your with clause:


$criteria->together = true;

That doesn’t seem to work, it still loads lazily…