Relations: Trying To Get Property Of Non-Object Error


I have in my model this relathions code:

'license'	=>	array(self::BELONGS_TO, 'License', 'license_id'),

In my model`s table I have license_id column and I have a License model…

In a view file I wrote

<?php echo $model->license->id; ?>

And I got error: Trying to get property of non-object.

Why is that happens? I have another relations (belongs_to!) in the same model that works…


Yii couldn’t load the related model. That is because either license_id is null or contains an invalid value that doesn’t exist in the other table.