laravel orm调用count方法会不理会其他的一些参数

在一个ORM实体类中, 我使用如下代码:

$this->where('status', 1)
->where('user_id', '<>', NULL)
->distinct('gateway_id')
->select(\DB::raw('distinct(`gateway_id`)'))
->count('gateway_id');

打印出来的sql是:select count(*) as aggregate from `user_gateway_bind` where `status` = ? and `user_id` is not null==>params{[1]}
这里我想想中的sql不一致, 我想象中的SQL是select distinct(gateway_id)这种
下面是正常的ORM调用方式
$this->where('status', 1)
->where('user_id', '<>', NULL)
->distinct('gateway_id')
->count('gateway_id');

使用ORM的时候我经常会忘记count方法是可以进入实参的, distinct方法我在源代码中看到是没有参数中, 这里写了参数也不会报错, 不知道为什么。
最近一段时间都是在写代码,没怎么去看源代码, 感觉需要去看下源代码了。

posted @ 2016-09-13 11:52  祥子爱游戏  阅读(345)  评论(0编辑  收藏  举报