鍍金池/ 問答/PHP  網(wǎng)絡安全/ thinkphp JOIN操作后左表的ID出問題了

thinkphp JOIN操作后左表的ID出問題了

thinkphp5

有3個表
article:id、type_id、author_id
type:id、type_name
author:id、author_name

控制器里加載了article模型

$artilcelist = ArtilceModel::alias('a')
        ->join('type b','a.type_id = b.id')
        ->join('author c','a.author_id = c.id')
        ->order('a.id desc')
        ->select();
        

在前臺用volist輸出:

{volist name="artilcelist" id="news"}
{$news.id}
{$news.type_name}
{$news.author_name}
{/volist}

其中{$news.type_name}、{$news.author_name}沒有問題,但{$news.id}顯示的ID是author表里的ID,而不是article。如果將2個join語句替換順序,顯示的就是type表里的ID。

請問如何能將article里的ID正確輸出,謝謝。

自己想到個辦法,在order之前,

->field('a.id,b.type_name,c.author_name')

通過filed的設定值顯示article里的id

回答
編輯回答
瘋浪

假如需要三個表的id
->field('a.id as aid ,b.id as bid ,c.id as cid')

2018年6月11日 18:00