Relations as variables issue

Hi all,

I had an application which I start to write when Yii has 1.0.3 or 1.0.4 release. Now, I updated into 1.0.7 I realized following problems for News AR model which I have.


[/b]I’ve defined News AR class which consist of following relations:

   public function relations()


     return array(

       'author'        =>array(self::BELONGS_TO, 'User',         'author_id'),

       'comments'      =>array(self::HAS_MANY,   'NewsComment',  'news_id'),

       'category'      =>array(self::HAS_MANY,   'NewsCategory', 'news_id'),

       'txt'           =>array(self::HAS_ONE,    'NewsTxt',      'news_id'),






         'joinType'=>'INNER JOIN',






When I’m trying to do create text for news, by creating new NewsTxt instance and assign it to txt property of above AR its not allowed anymore. Following error message is displayed:

Additionally I was using txt property in views in following way:

       <?php echo CHtml::activeLabelEx($news->txt,'text'); ?>

       <?php echo CHtml::activeTextArea($news->txt,'text',array('rows'=>20, 'cols'=>45)); ?>


I’m not allowed to do this to. Error message is:

Any idea why?

Cheers, aztech

Yes, there is a change that a new AR object is not allowed to be assigned a related object (doesn’t make sense). So your code will fail.

I was using this feature to manage (in easy way) has_one relationship. A specially together with afterSave() method

   protected function afterSave()


     //create new

     if ($this->isNewRecord)



       $this->txt->save();        //here I'm creating news text


     //... some ohter code


How I can replace such functionality in Yii way?

As far as I know, related objects are saved as well when you ‘hit’ save on main model.

You convinced me to add back the support for assigning a related object to an AR object. It’s in SVN now. Thanks.