相關關鍵詞
關于我們
最新文章
PHP中Laravel 關聯(lián)查詢返回錯誤id的解決方法
在 Laravel Eloquent 中使用 join 關聯(lián)查詢,如果兩張表有名稱相同的字段,如 id,那么它的值會默認被后來的同名字段重寫,返回不是期望的結果。例如以下關聯(lián)查詢:
PHP
$priority = Priority::rightJoin('touch', 'priorities.touch_id', '=', 'touch.id') ->where('priorities.type', 1) ->orderBy('priorities.total_score', 'desc') ->orderBy('touch.created_at', 'desc') ->get();