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. Veryy soo this web page will be famous among all blog people, ddue to it's fastidious content

    Reply
  2. After looking at a number of the articles on your website, I truly appreciate your way of blogging. I bookmarked it to my bookmark website list and will be checking back in the near future. Please check out my website too and tell me how you feel.

    Reply
  3. Nice blog! Is your theme custom made or did you download it from somewhere? A theme like yours with a few simple adjustements would really make my blog jump out. Please let me know where you got your design. Many thanks

    Reply
  4. Thanks on your marvelous posting! I certainly enjoyed reading it, you could be a great author.I will always bookmark your blog and will come back sometime soon. I want to encourage continue your great writing, have a nice day!

    Reply
  5. I love this

    Reply
  6. Touche. Sound arguments. Keep upp the good spirit.

    Reply