>  기사  >  백엔드 개발  >  thinkphp+mysql中出现的关联模型问题?

thinkphp+mysql中出现的关联模型问题?

WBOY
WBOY원래의
2016-06-06 20:23:311164검색

我定义了一张关系表MemberSchool,里面存放的字段有college_id,senior_id,major_id
还有另外三张表college,senior,major表
这是我原先用查询语言的代码

<code>$memberSchool = M('Memberschool');
$where['member_id'] = array('EQ',$this->member_id);
$result = $memberSchool->field('college_name,major_name,school_name')
            ->join('JOIN __COLLEGE__ ON
               __MEMBERSCHOOL__.college_id = __COLLEGE__.college_id')
            ->join('JOIN __SENIOR__ ON
               __MEMBERSCHOOL__.senior_id = __SENIOR__.id')
            ->join('JOIN __MAJOR__ ON
            __MEMBERSCHOOL__.major_id = __MAJOR__.major_id')
            ->where($where)
            ->find();
        return $result;</code>

现在我想利用关联模型的语句把他们的数据查询出来,请问要怎么查询呢?要以哪个表作为参照表呢?

回复内容:

我定义了一张关系表MemberSchool,里面存放的字段有college_id,senior_id,major_id
还有另外三张表college,senior,major表
这是我原先用查询语言的代码

<code>$memberSchool = M('Memberschool');
$where['member_id'] = array('EQ',$this->member_id);
$result = $memberSchool->field('college_name,major_name,school_name')
            ->join('JOIN __COLLEGE__ ON
               __MEMBERSCHOOL__.college_id = __COLLEGE__.college_id')
            ->join('JOIN __SENIOR__ ON
               __MEMBERSCHOOL__.senior_id = __SENIOR__.id')
            ->join('JOIN __MAJOR__ ON
            __MEMBERSCHOOL__.major_id = __MAJOR__.major_id')
            ->where($where)
            ->find();
        return $result;</code>

现在我想利用关联模型的语句把他们的数据查询出来,请问要怎么查询呢?要以哪个表作为参照表呢?

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.