Laravel Eloquent - update with join



我尝试用join做更新,但它不工作…没有错误

有什么想法吗?

$updates = Schedule::join('production_wip', function ($q) {
$q->on('schedule.DJ_NBR', '=', 'production_wip.DJ_NBR')
->on('schedule.dept_code', '=', 'production_wip.Dept_Code');
})
->where('schedule.skipped', '!=', 1)->whereNull('schedule.actual_production')
->update(['schedule.skipped' => 1]);

试着调试一下:

DB::enableQueryLog();
$results = Schedule::join('production_wip', function ($q) {
$q->on('schedule.DJ_NBR', '=', 'production_wip.DJ_NBR')
->on('schedule.dept_code', '=', 'production_wip.Dept_Code');
})
->where('schedule.skipped', '!=', 1)->whereNull('schedule.actual_production')
->get();
dd($results, DB::getQueryLog());

为了确保你的查询正在影响一些行(你可以检查生成的SQL并在Sequel Ace(或任何其他DB管理器)中尝试)

我敢打赌,问题是要么你的数据格式不一样在你的2个表,或者你没有数据匹配你的were()

最新更新