Association model problems in thinkphp + mysql?

Source: Internet
Author: User
I have defined a relational table MemberSchool. The fields in the table include college_id, senior_id, major_id, and three other tables, college, senior, major table. This is the code I used to query the language {code ...} now I want to use the Statement of the associated model to query their data... I have defined a relational table MemberSchool. The fields in the table include college_id, senior_id, and major_id.
There are three other tables: college, senior, and major.
This is the code I used to query the language.

$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;

Now I want to use the Statement of the associated model to query their data. How can I query it? Which table is used as the reference table?

Reply content:

I have defined a relational table MemberSchool. The fields in the table include college_id, senior_id, and major_id.
There are three other tables: college, senior, and major.
This is the code I used to query the language.

$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;

Now I want to use the Statement of the associated model to query their data. How can I query it? Which table is used as the reference table?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.