我有下面的表格。没有遵循Laravel约定。表格
helpdesk_logs (table)
id primary_key
helpdesk_files (table)
id primary_key
helpdesk_logs_id - foreign_key模型
HelpdeskLogs.php
public function helpdeskFiles(){
return $this->hasMany( 'Defsys\Modules\helpdesk\Models\HelpdeskFiles','helpdesk_logs_id','id');
}HelpdeskFiles.php
public function helpdeskLogs()
{
return $this->belongsTo( 'Defsys\Modules\helpdesk\Models\HelpdeskLogs','helpdesk_logs_id' );
}我正在执行以下任务
HelpdeskLogs::with('helpdeskFiles')
->select( DB::raw( 'helpdesk_logs.id AS helpdesk_logs_id,helpdesk_logs.description,helpdesk_logs.status ,helpdesk_logs.spent_time' ) )
->where( 'helpdesk_logs.id', 13)->get();尽管helpdesk_files(针对helpdesk_lod_id 13)中有记录,但它不会返回任何记录。绑定参数显示为空
当我调试查询时,它显示如下
1 => array:3 [▼
"query" => "select * from `helpdesk_files` where `helpdesk_files`.`helpdesk_logs_id` in (?)"
"bindings" => array:1 [▼
0 => null
]
"time" => 0.17
]发布于 2016-09-07 15:25:26
在您的服务台日志中,表id colunn可用于检索所需的结果HelpdeskLogs::with('helpdeskFiles')->where( 'id', 13)->get();
https://stackoverflow.com/questions/39363259
复制相似问题