{"action":"created","issue":{"url":"https://api.github.com/repos/phalcon/cphalcon/issues/11395","repository_url":"https://api.github.com/repos/phalcon/cphalcon","labels_url":"https://api.github.com/repos/phalcon/cphalcon/issues/11395/labels{/name}","comments_url":"https://api.github.com/repos/phalcon/cphalcon/issues/11395/comments","events_url":"https://api.github.com/repos/phalcon/cphalcon/issues/11395/events","html_url":"https://github.com/phalcon/cphalcon/issues/11395","id":132625268,"number":11395,"title":"2.0.10: Fatal error with Query Builder + Count + Group By + Paginator","user":{"login":"hailie-rei","id":12576900,"avatar_url":"https://avatars.githubusercontent.com/u/12576900?v=3","gravatar_id":"","url":"https://api.github.com/users/hailie-rei","html_url":"https://github.com/hailie-rei","followers_url":"https://api.github.com/users/hailie-rei/followers","following_url":"https://api.github.com/users/hailie-rei/following{/other_user}","gists_url":"https://api.github.com/users/hailie-rei/gists{/gist_id}","starred_url":"https://api.github.com/users/hailie-rei/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hailie-rei/subscriptions","organizations_url":"https://api.github.com/users/hailie-rei/orgs","repos_url":"https://api.github.com/users/hailie-rei/repos","events_url":"https://api.github.com/users/hailie-rei/events{/privacy}","received_events_url":"https://api.github.com/users/hailie-rei/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2016-02-10T07:16:24Z","updated_at":"2016-03-18T08:58:07Z","closed_at":null,"body":"@sergeyklay \r\n\r\n == See the next comment == \r\n\r\nI use Phalcon 2.0.8.\r\n\r\n```php\r\nuse Phalcon\\Paginator\\Adapter\\QueryBuilder as PaginatorModel;\r\n\r\n        $data = $this->getModelsManager()->createBuilder()\r\n            ->from(array('a' => '\\Db\\Article'))\r\n            ->columns(array(\r\n                'a.*',\r\n                'COUNT(ac.id) AS c'\r\n            ))\r\n            ->leftJoin('\\Db\\ArticleComment', 'a.id = ac.article_id', 'ac')\r\n            ->where('a.status = :status:', array('status' => 'approved'))\r\n            ->orderBy(array('a.date_post DESC', 'a.date_add DESC'))\r\n            ->groupBy('a.id')\r\n        ;\r\n        $paginator = new PaginatorModel(array(\r\n            'builder' => $data,\r\n            'limit' => 10,\r\n            'page' => 1\r\n        ));\r\n        $paginate = $paginator->getPaginate();\r\n        var_dump($paginate->total_items); die;\r\n```\r\n\r\nreturns: int(1)\r\n\r\nWorking example with data instead of query builder object for Paginator:\r\n\r\n```php\r\nuse Phalcon\\Paginator\\Adapter\\Model as PaginatorModel;\r\n\r\n        $data = $this->getModelsManager()->createBuilder()\r\n            ->from(array('a' => '\\Db\\Article'))\r\n            ->columns(array(\r\n                'a.*',\r\n                'COUNT(ac.id) AS c'\r\n            ))\r\n            ->leftJoin('\\Db\\ArticleComment', 'a.id = ac.article_id', 'ac')\r\n            ->where('a.status = :status:', array('status' => 'approved'))\r\n            ->orderBy(array('a.date_post DESC', 'a.date_add DESC'))\r\n            ->groupBy('a.id')\r\n            ->getQuery()->execute();\r\n        $paginator = new PaginatorModel(array(\r\n            'data' => $data,\r\n            'limit' => 10,\r\n            'page' => 1\r\n        ));\r\n        $paginate = $paginator->getPaginate();\r\n        var_dump($paginate->total_items); die;\r\n```\r\n\r\nreturns: int(62)\r\n\r\nMy tables: \r\n```sql\r\n`CREATE TABLE `article` (\r\n  `id` int(11) NOT NULL AUTO_INCREMENT,\r\n  `title` tinytext NOT NULL,\r\n  `text` mediumtext NOT NULL,\r\n  `date_add` datetime NOT NULL,\r\n  `user_id` int(11) NOT NULL,\r\n  `status` enum('new','approved','declined','deleted') NOT NULL,\r\n  `view_count` int(11) NOT NULL DEFAULT '0',\r\n  `keywords` text,\r\n  `description` text,\r\n  `date_post` date NOT NULL,\r\n  PRIMARY KEY (`id`),\r\n  KEY `user_id` (`user_id`),\r\n  KEY `status` (`status`),\r\n  KEY `date_post` (`date_post`)\r\n) ENGINE=InnoDB AUTO_INCREMENT=63 DEFAULT CHARSET=utf8;\r\n\r\nCREATE TABLE `article_comment` (\r\n  `id` int(11) NOT NULL AUTO_INCREMENT,\r\n  `article_id` int(11) NOT NULL,\r\n  `parent_id` int(11) NOT NULL DEFAULT '0',\r\n  `user_id` int(11) NOT NULL DEFAULT '0',\r\n  `user_name` tinytext,\r\n  `comment` text NOT NULL,\r\n  `date_add` datetime NOT NULL,\r\n  `status` enum('new','approved','declined') NOT NULL DEFAULT 'new',\r\n  PRIMARY KEY (`id`),\r\n  KEY `index` (`article_id`,`parent_id`,`user_id`)\r\n) ENGINE=InnoDB AUTO_INCREMENT=12 DEFAULT CHARSET=utf8;\r\n```\r\n\r\nI guess problem is somewhere here: https://github.com/phalcon/cphalcon/blob/master/phalcon/paginator/adapter/querybuilder.zep#L189\r\n\r\nJust to compare: https://github.com/phalcon/cphalcon/blob/master/phalcon/paginator/adapter/model.zep#L97 n is total items count. This code works.\r\n"},"comment":{"url":"https://api.github.com/repos/phalcon/cphalcon/issues/comments/198264536","html_url":"https://github.com/phalcon/cphalcon/issues/11395#issuecomment-198264536","issue_url":"https://api.github.com/repos/phalcon/cphalcon/issues/11395","id":198264536,"user":{"login":"sergeyklay","id":1256298,"avatar_url":"https://avatars.githubusercontent.com/u/1256298?v=3","gravatar_id":"","url":"https://api.github.com/users/sergeyklay","html_url":"https://github.com/sergeyklay","followers_url":"https://api.github.com/users/sergeyklay/followers","following_url":"https://api.github.com/users/sergeyklay/following{/other_user}","gists_url":"https://api.github.com/users/sergeyklay/gists{/gist_id}","starred_url":"https://api.github.com/users/sergeyklay/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sergeyklay/subscriptions","organizations_url":"https://api.github.com/users/sergeyklay/orgs","repos_url":"https://api.github.com/users/sergeyklay/repos","events_url":"https://api.github.com/users/sergeyklay/events{/privacy}","received_events_url":"https://api.github.com/users/sergeyklay/received_events","type":"User","site_admin":false},"created_at":"2016-03-18T08:58:07Z","updated_at":"2016-03-18T08:58:07Z","body":"@hailie-rei @Gigabiter Could you please test 2.1.x branch?"}}