【发布时间】:2016-01-18 05:06:25
【问题描述】:
由于某种原因,我在执行以下操作时没有得到预期的结果:
$cars = Car::query();
$cars->whereIsVisible(true);
# output: $list
// [2016-01-16 09:30:04] local.INFO: array (
// 0 => 5,
// 1 => 7,
// 2 => 9,
// 3 => 3,
// )
$cars->whereHas('specifications', function($query) use ($list) {
$query->whereIn('id', ($list));
});
$cars->get();
我所期望的是,我只得到具有该 $list 中所有规格的汽车,但这是不正确的。即使我填写更多规格,我也会得到更大的结果。所以出了点问题。
我习惯了 Eloquent,所以我很喜欢查询。但这是查询:
select * from "cars" where "cars"."deleted_at" is null
and "is_visible" = true
and (select count(*)
from "specs" inner join "car_specs"
on "specs"."id" = "car_specs"."facility_id"
where "car_specs"."car_id" = "cars"."id"
and "id" in (5, 7, 9 ,3)) >= 1
有人知道哪里出错了吗?以及如何解决?
【问题讨论】: