我正在加入page_content
表,之后两个表都有sef_url
列
以下代码返回错误。
是否有可能在CDbCriteria->select
$criteria=new CDbCriteria;
$criteria->alias = 'p';
$criteria->select = array('p.sef_url, p.date_last_modified, pc.sef_url AS parent_sef_url');
$criteria->join = 'LEFT JOIN page_content pc ON p.parent_pageid = pc.pageid';
$criteria->condition = 'p.published=:published AND p.sitemap_index=:sitemap_index';
$criteria->params = array(':published'=>1,':sitemap_index'=>0);
$result_arr = parent::model()->findAll($criteria);
echo '<pre>';
print_r($result_arr);
foreach($result_arr as $row) {
echo $row['parent_sef_url'];
}
答案 0 :(得分:0)
您还应该定义一个关系:
public function relations()
{
return array(
'parentPageContent'=>array(self::BELONGS_TO, 'PageItem', 'parent_pageid'),
);
}
在你能做到之后:
$pageContents = PageContent::model()->with('parentPageContent')->findAllByAttributes(array(':published'=>1,':sitemap_index'=>0));
foreach($pageContents as $pageContent){
echo $pageContent->parentPageContent->sef_url;
}