两个在Laravel Eloquent查询中的位置

时间:2015-11-12 15:31:07

标签: laravel eloquent

我有以下查询,简化如下。

$property = Property::whereHas('features', function ($q1) use ($features) {
            $q1->where(function ($sub) use ($features) {
                $sub->whereIn('features.FeatureID', $features);
            });
            $q1->groupBy('PropertyID');
            $q1->having('count(*)', '=', count($features));
        })
        ->whereHas('Week', function ($q) use ($nights) {
            $q->where(function ($sub) use ($nights) {
                $sub->whereIn('priceAvailDate', $nights);
            });
            $q->groupBy('PropertyID');
            $q->having('count(*)', '=', count($nights));
        })
        ->get();

如果我拿出一个已经出去的地方,我会收到预期的收藏品。如果我拿出另一个我得到了预期的结果。就在他们在一起的时候我什么也没有回来。我假设它有两个计数(*)。我知道我有数据,其中两个地方都是真的。

SQL输出

select * from `tblproperties` where (select count(*) from `features` inner 
join `propertyfeatures` on `features`.`featureid` = 
`propertyfeatures`.`FeatureID` where `propertyfeatures`.`PropertyID` = 
`tblproperties`.`PropertyID` and (`features`.`FeatureID` in (?)) group by 
`PropertyID` having `count(*)` = ?) >= 1 and (select count(*) from 
`tblpriceavail` where `tblpriceavail`.`propertyID` =     `tblproperties`.`PropertyID` 
and (`priceAvailDate` in (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)) group by 
`PropertyID` having `count(*)` = ?) >= 1

修正了,虽然不是100%肯定为什么。使用havingRaw而不是工作。

即。更改$ q->有('count(*)','=',count($ nights));

到$ q-> havingRaw('count(*)='。count($ nights));

0 个答案:

没有答案