我刚注意到我的where status = blocked
未被考虑
查询仍然返回阻止和活动状态。
$contacts = DB::table('contacts')
->where('uid_by', $me)
->orWhere('uid_to', $me)
->where('status', 'blocked')
->select(
DB::raw("IF(uid_by = $me, uid_to, uid_by) AS user_id")
)
->get();
查询可能有什么问题?
我尝试记录正在执行的查询:
{"query":"select IF(uid_by = 3, uid_to, uid_by) AS user_id from `contacts` where `uid_by` = ? or `uid_to` = ? and `status` = ?","bindings":[3,3,"blocked"],"time":0}
使用:
$queries = DB::getQueryLog();
return $last_query = end($queries);
答案 0 :(得分:2)
尝试切换where语句,如下所示:
$contacts = DB::table('contacts')
->where('uid_by', $me)
->where('status', 'blocked')
->orWhere('uid_to', $me)
->select(
DB::raw("IF(uid_by = $me, uid_to, uid_by) AS user_id")
)->get();
正在发生的事情是,不评估OR
关键字之后的内容,因此显示所有已屏蔽和有效...