我尝试添加带有model::with的附加列
$pitchChech = Pitch::with(['prices'=>function ($query){
$query->select('*',\DB::Raw("(select sum(HOUR(TIMEDIFF(valid_to ,valid_from))) from pitch_price as xpitch_price where pitch_id = pitch_price.pitch_id ) as x "))
->whereRaw(" x < ?",[24]);
}])->get();
dd($pitchChech);
我有这个输出
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'x' in 'where clause'
我不明白是什么问题,我使用拉维5.1,但我不认为有问题与ut
1条答案
按热度按时间zqry0prt1#
对于派生列,必须使用
having()
: