thinkphp的关联模型方面的求助

浏览:499 发布日期:2013/10/14 分类:求助交流
新闻表

分类表

NewsModel.class.php<?php
 class NewsModel extends RelationModel
 {
     protected $_link = array(
        'news_category'=> array(  
                    'mapping_type'=>BELONGS_TO,
                    'class_name'=>'news_category',
                    'foreign_key'=>'cat_id',
                    'mapping_limit'=>10,
                    'mapping_name'=>'news_category',
                    'as_fields'=>'cat_name'//查询字段
                  
       )
    );
 }
?>
IndexAction.class.phpclass IndexAction extends Action {
    public function index(){
     $re = D('News');
     
     $categorylist=$re->relation(true)->field('title')->limit(10)->select();
     
     print_r($categorylist);
     $this->display();
    }
}
我要查出新闻的title字段是哪个分类的
但是cat_name为空?
最佳答案
评论( 相关
后面还有条评论,点击查看>>