Skip to content

Model Pagination: Problem with total rows #1318

Description

@enix-app

I'm using SQLite3 driver and I have problem with total rows when I use
COUNT() function and GROUP BY clause.

{
    "total": 2,
    "currentPage": 1,
    "perPage": 10,
    "pageCount": 1,
    "next": null,
    "previous": null,
    "results": [
        {
          ....
        },
        {
          ....
        },
        {
          ....
        },
        {
          ....
        },
        {
          ....
        },
        {
          ....
        }
    ]
}

My model:

<?php

class Category extends \CodeIgniter\Model {

    protected $table = 'category c';
    
    // ....
    
    public function _findAll()
    {
        $this
            ->select("
                c.Name,
                c.Title,
                COUNT(p.Id) PostCount
            ")
            ->join("post p", "p.IdCategory = c.Id", "left")
            ->groupBy("c.Id")
        ;
    }

}

Awesome Framework!
Thank you.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions