我定義了一張關係表MemberSchool,裡面存放的欄位有college_id,senior_id,major_id
還有另外三張表college,senior,major表
這是我原先用查詢語言的代碼
$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;
現在我想利用關聯模型的語句把他們的資料查詢出來,請問要怎麼查詢呢?要以哪個表作為參照表呢?
回複內容:
我定義了一張關係表MemberSchool,裡面存放的欄位有college_id,senior_id,major_id
還有另外三張表college,senior,major表
這是我原先用查詢語言的代碼
$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;
現在我想利用關聯模型的語句把他們的資料查詢出來,請問要怎麼查詢呢?要以哪個表作為參照表呢?