What are the associated model problems that occur in Thinkphp+mysql?

Source: Internet
Author: User
I have defined a relational table Memberschool, which contains the fields college_id,senior_id,major_id
There's another three tables college,senior,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 association model to query their data out, how to query it? Which table do you want to use as a reference table?

Reply content:

I have defined a relational table Memberschool, which contains the fields college_id,senior_id,major_id
There's another three tables college,senior,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 association model to query their data out, how to query it? Which table do you want to use as a reference table?

  • Related Article

    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.