Access only eager loaded ARs

I have medium complex DB model - Flyer, which has MANY Pages, which has MANY_MANY Tags

I got correct setup of relations:

models/Flyer.php




public function relations()

{

	return array(

		'pages' => array(self::HAS_MANY, 'Page', 'flyerId'),

	);

}



models/Page.php




public function relations()

{

	return array(

		'flyer' => array(self::BELONGS_TO, 'Flyer', 'flyerId'),

		'tags' => array(self::MANY_MANY, 'Tag', 'PageHasTag(pageId, tagId)'),

	);

}



models/Tag.php have empty relations, I don’t need to access related objects from $tag instances.

OK, now I’m in situation, that I’m searching Flyers, which contains specific tag. This can be easily accomplished with criteria like this:




$criteria = new CDbCriteria();

$criteria->together = TRUE;

$criteria->group = '`t`.`id`';

$criteria->params = array();

$criteria->addSearchCondition('`tags`.`name`', $searchModel->query);

$criteria->with[] = 'pages.tags';



But now, I need some way to fetch Page number(s), which contains specified Tag name. By putting this $criteria into findAll(), I get eager loaded Pages on resulting Flyer set. When iterating through this set (of Flyers), I want fetch only Pages that are already loaded (they correspond to my search query).

But I don’t know how to accomplish this (fetch only eagerly loaded Pages), cos accessing $flyer->pages, will lazy load missing Pages.

Can I access only eagerly loaded related ARs? Is there other solution how to solve this exaple - serching through Flyers by Tags and fetching corresponding Page number(s) on Flyer set?

Thanks.

Did you try this?




$criteria->with = array('pages', 'pages.tags');