我在我的Laravel应用程序中使用SQLite并尝试运行whereHas
查询:
$payments = Payment::whereHas('payers', function($q){
$q->where('user_id', '=', 1);
})->get();
这将返回一个空结果,这是由于整数1被强制转换为字符串,由laravel / eloquent生成的结果查询证明:
select * from "payments" where (select count(*) from "payers" inner join "payer_payment" on "payers"."id" = "payer_payment"."payer_id" where "payer_payment"."payment_id" = "payments"."id" and "user_id" = 1) >= '1'
经过审核this github issue我尝试使用DB::raw
,如此:
$payments = Payment::whereHas('payers', function($q){
$q->where('user_id', '=', DB::raw(1));
})->get();
但没有改善。如何在不更改数据库驱动程序的情况下解决此问题?
答案 0 :(得分:0)
$payments = Payment::whereHas('payers', function($q){
$q->where('user_id', '=', 1);
}, '>=', DB::raw(1))->get();