CActiveDataProvider wierd behavior

I have this lines of code…




        echo '<pre>';

	print_r($data->ProductCategory->prd_cat_name);

	die();



…it does show the correct output when "die()" is executed, but, when I remove the "die()" it throws

"Trying to get property of non-object" on the exact same line on "print_r"

Here is my Model relation




public function relations()

	{

		return array(

			'ProductCategory'=>array(self::HAS_ONE, 'ProductCategory', 'prd_cat_id'),

			'ProductType'=>array(self::HAS_ONE, 'ProductType', 'prd_typ_id'),

			'ProductStyle'=>array(self::HAS_ONE, 'ProductStyle', 'prd_sty_id'),

		);

	}



Controller




public function actionIndex()

	{

		$dataProvider=new CActiveDataProvider('Product', array(

			'criteria'=>array(

				'with'=>array('ProductCategory'),

			),

		));

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

			'dataProvider'=>$dataProvider,

		));

	}



You are missing related data in the relation.

You need to test to see if $model->property is set (has related data) or not.

Could you please explain this with more details? This is the same problem that I have.

Exactly my problem.