CDetailView Widget / Relational MySQL

Hi,

i have a problem in displaying relational data. The situation is like this: My models are contacts and locations.

Contacts.php:


public function relations()

	{

		return array(

			'locations' => array(self::HAS_MANY, 'Locations', 'contact_id'),

			'persons' => array(self::HAS_MANY, 'Persons', 'contact_id'),


		);

	}



view.php:


<h1>View Contacts #<?php echo $model->id; ?></h1>


<?php $this->widget('zii.widgets.CDetailView', array(

	'data'=>$model,

	'attributes'=>array(

		'id',

		'name',		

	),

));




?><h2>Locations</h2>

<?php 

	$locations = Locations::model()->find("contact_id",$model->id);

	$i=-1;

	while($i++<count($locations)) {

			$this->widget('zii.widgets.CDetailView', array(

			'data'=>$locations,

			'attributes'=>array(

				'id',

				'street',

				'nr',

				'zip',

				'city',

				'country',

				

			),

		));

	}




?>

Somehow only 1 location is displayed even if there are two in the db. What am i doing wrong!?

Thanks for your help…

Flo

ContactsController.php




	public function actionView()

	{

		$contact = $this->loadModel();

		$this->render('view',array(

			'model'=>$contact,

			'locations'=>$contact->locations,

		));

	}



view.php




foreach($locations as $location)

{

                     $this->widget('zii.widgets.CDetailView', array(

                        'data'=>$location,

                        'attributes'=>array(

                                'id',

                                'street',

                                'nr',

                                'zip',

                                'city',

                                'country',

                                

                        ),

                ));


}



It worked… thanks a lot!