Yii2 dataProvider返回数据条数跟指定pageSize不一致

前两天在编码的过程中,发现使用dataProvider返回的数据条数很奇怪,跟设置的pageSize不一致,而且还是没有规律的那种:

/** @var $provider ActiveDataProvider*/
$provider = new ActiveDataProvider([

    'query' => $query,
    'pagination' => [
        'page' => $currentPage - 1,
        'pageSize' => $pageSize,
    ],
    'sort' => [
        'defaultOrder' => [
            'order_id' => SORT_DESC,
        ]
    ]

]);

比如指定的pageSize是10,但是返回的不是10条,有的页码只有两条

返回结果

一直不知道原因,文档也查不到,搜索也无果,后来问了同事,需要在查询的query加上groupBy();

果真加上就好了,目前还不知道原理,先mark后面再看。

query 加上groupBy

结果正常了:

结果正常

Responses
  1. My brother recommended I might like this website. He was entirely right. This post truly made my day. You cann’t imagine simply how much time I had spent for this info! Thanks!

    Reply
  2. I’m not really a internet reader to be honest but your site is really nice, keep it up! I’ll go ahead and bookmark your website to come back in the future. Many thanks

    Reply
  3. Great post, I genuinely enjoyed reading it

    Reply
  4. I'm really loving the theme/design of your blog. Do you ever run into any web browser compatibility problems? A few of my blog visitors have complained about my website not working correctly in Explorer but looks great in Firefox. Do you have any suggestions to help fix this issue?

    Reply
  5. コールマンの勝ち目はこちら。ニュースです。コールマンをへべれけに働かすしたい。いろいろな情報です。

    Reply
  6. Very good website you have here but I was curious about if you knew of any message boards that cover the same topics discussed here? I'd really love to be a part of group where I can get opinions from other experienced people that share the same interest. If you have any recommendations, please let me know. Many thanks!

    Reply