如何实现这个查询?
Sale::with(['catalog'])
->whereIn('id', $ids)
->update(['price' => DB::raw('catalog.price')]);
这个不起作用,它显示未定义的表... 我试着输入表的名字,但结果还是一样。
在互联网上,我总是找到简单的查询:
Sale::with(['catalog'])
->whereIn('id', $ids)
->update(['price' => 5]);
好的!当我想要更新所有行为相同值时,这很容易。此外,如果您想使用同一表的列进行更新,也很容易,就像:
Sale::with(['catalog'])
->whereIn('id', $ids)
->update(['price' => DB::raw('price_alternative')]);
那么如何使用另一个具有关联关系的表的列呢?我还没有找到解决办法。
我知道可以使用整个原始查询来解决,但是我想知道是否可以通过Eloquent方式实现。