Effeciant way to iterate through large CActiveRecord

Yeah, another MANY to MANY question.

I have the following tables

children

guardians_children

guardians

carriers

The logical ownership could also be illustrated like this.

children->guardians_children->guardians->carriers

Here are the relations;

children:




public function relations()

	{

		// NOTE: you may need to adjust the relation name and the related

		// class name for the relations automatically generated below.

		return array(

			'guardians_children' => array(self::HAS_MANY,'Guardians_Children','childrenId'),

		);

	}



guardians_children:




	public function relations()

	{

		// NOTE: you may need to adjust the relation name and the related

		// class name for the relations automatically generated below.

		return array(

			'children' => array(self::BELONGS_TO,'Children','id'),

			'guardians' => array(self::HAS_MANY,'Guardians','id'),

		);

	}



guardians:




	public function relations()

	{

		// NOTE: you may need to adjust the relation name and the related

		// class name for the relations automatically generated below.

		return array(

			'guardians_children' => array(self::BELONGS_TO, 'Guardians_Children', 'id'),

                        'carriers' => array(self::HAS_ONE,'Carriers','id'),

		);

	}



From the ChildrenController, I am calling a method in the Children model that returns all the related information about the child. And it works just fine, as when I DUMP the object, I can see that it is all there. But I am not understanding the most efficient way to iterate over the object to say, get the guardian’s names, or the carrierId for example.

TIP: TURN ON LOGGING!

I wasn’t joining the relations of the models correctly. Therefore the result wasn’t really giving me what I thought it was. It was only by evaluating the underlying SQL, that I was able to correct the problem.

Here is the configuration for logging that I have enabled on my TEST instance.

../protected/config/main.php




		'log'=>array(

			'class'=>'CLogRouter',

			'routes'=>array(

				array(

					'class'=>'CFileLogRoute',

					'levels'=>'error, warning',

				),

                                array(

                                    'class'=>'CDbLogRoute',

                                    'levels'=>'error,warning',

                                    'autoCreateLogTable'=>true, //<------ be careful, this auto creates the table.

                                    'enabled'=>true,

                                    'connectionID'=>'db', //<------- pointer to the Yii::app()->db instance i believe.

                                ),

				// uncomment the following to show log messages on web pages

				array(

					'class'=>'CWebLogRoute',

				),

			),

		),