2つのテーブルがあります:
コンテンツ
id | text
------------
1 | text1
2 | text2
3 | text3
4 | text4
写真
id | content_id | src
-----------------------------
1 | 1 | img1.png
2 | 1 | img2.png
3 | 2 | img3.png
4 | 3 | img1.png
3番目のコントローラーから左に結合された写真を含むコンテンツを取得しようとしています。
私のコード:
$oDBC = new CDbCriteria();
$oDBC->select = 't.*,p.*';
$oDBC->join = 'LEFT JOIN photos p ON t.id = p.content_id';
$oDBC->condition = 't.step_id = "'.$model->id.'"';
$content = Content::model()->find($oDBC);
ContentControllerに追加された関数:
public function relations()
{
return array('photos' => array(self::HAS_MANY, 'Photos', 'content_id');
}
ただしprint_r($content)
、写真データではなく、コンテンツデータのみを返します。
この答えのように私は試しました:
print_r($content->photos);
しかし得たProperty "Content.photos" is not defined.
私は何が間違っているのですか?