求助:一对多模型关联 调用关联方法

浏览:1843 发布日期:2017/02/25 分类:ThinkPHP5专区 关键字: tp5 模型 关联模型
这是控制器里面的代码:  public function index()
    {
        
        $article =  Article::get(2);
        $res  = $article->comm()->where('id=2')->find();
        dump($res);die;
        exit();
        return $this->fetch('index/login');
    }
这是模型代码:<?php 
    namespace app\admin\model;
    use think\Model;
    class Article extends Model{
        
        //定义关联方法
        protected function comm(){
            return $this->hasMany('Content','article_id','id');
        } 
    }
?>
结果运行的时候报错:method not exist:think\db\Query->comm



不理解哪里出错了?????
最佳答案
评论( 相关
后面还有条评论,点击查看>>