The sample of linked tables

Good afternoon.
Please help me to understand. How to get the values
communication article.category in the sample,

ArticleData::model()->with('article','article.category')->findAll();


Try this:
$article = ArticleData::model()->with('article','article.category')->findAll();
echo $article[0]->article->category->title;

But, null is returned.

Model:

<?php
class Category extends CActiveRecord
{
 public static function model($className=__CLASS__)
{
 return parent::model($className);
}

 public function tableName()
{
 return 'TBL_CATEGORY';
}

 public function relations()
{
 return array(
 'article'=-->array(self::HAS_MANY, 'Articles','category'),
);
}
}
?>

<?php
class Articles extends CActiveRecord
{
 public static function model($className=__CLASS__)
{
 return parent::model($className);
}

 public function tableName()
{
 return 'TBL_ARTICLES';
}

 public function relations()
{
 return array(
 'data'=-->array(self::HAS_MANY, 'ArticleData','parentuuid'),
 'category'=>array(self::BELONGS_TO, 'Category','category'),
);
}
}
?>

<?php
class ArticleData extends CActiveRecord
{
 public static function model($className=__CLASS__)
{
 return parent::model($className);
}

 public function tableName()
{
 return 'TBL_ARTICLE_DATA';
}

 public function relations()
{
 return array(
 'article'=-->array(self::BELONGS_TO, 'Articles','parentuuid'),
 'language'=>array(self::BELONGS_TO, 'Languages','language'),
);
}
}?>
October 8th 19 at 01:06
1 answer
October 8th 19 at 01:08
Well, let's play telepaths :-)
Assumption first. You have turned off display errors notice and you do not see the error "trying to get property of non-object...", which occurs because in Articles you have and a category attribute and a relation with the same name.

Turn on the display of all errors.
error_reporting(E_ALL);<br> ini_set("display_errors", 1); <br>

If you have not guessed, then look in the log yii, the query that runs and does he like the truth.

By the way, no need to write with('article','article.category'), it is enough with('article.category').

Find more questions by tags Active RecordYii