Home >Backend Development >PHP Tutorial >thinkphp+mysql中出现的关联模型问题?

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

WBOY
WBOYOriginal
2016-06-06 20:23:311193browse

我定义了一张关系表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>

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

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn