Quantcast
Channel: Yii Framework Forum
Viewing all articles
Browse latest Browse all 18717

Error When Foreign Key Is Null

$
0
0
Hi,

is there a way to avoid the error
Trying to get property of non-object 
when the value of a foreign key is NULL.

I am a Yii beginner and I am wondering, because the following MySQL query on the command line (not in Yii) retrieves data even if the foreign key composer_Id is NULL:

SELECT * FROM `tbl_main` AS t
LEFT JOIN tbl_related AS rel
ON t.composer_Id = rel.Id


Using relations in Yii ActiveRecord I get an error, when there are records having an empty foreign key.

Relations in tbl_main model:
'composer'=>array(self::BELONGS_TO, 'tbl_related', 'composer_Id')

Relations in tbl_related model:
'items'=>array(self::HAS_MANY, 'tbl_main', 'composer_Id')


Thank you for hints.

Viewing all articles
Browse latest Browse all 18717

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>