{"action":"created","comment":{"url":"https://api.github.com/repos/orocrm/platform/pulls/comments/26288985","id":26288985,"diff_hunk":"@@ -95,7 +95,7 @@ public function getCountQueryBuilder(QueryBuilder $originalQb)\n             $this->addJoins($qb, $parts);\n         }\n         if (!$parts['groupBy']) {\n-            $fieldsToSelect[] = $this->getFieldFQN($this->idFieldName);\n+            $fieldsToSelect[] = sprintf('DISTINCT %s', $this->getIdFieldFQN());","path":"src/Oro/Bundle/BatchBundle/ORM/QueryBuilder/CountQueryBuilderOptimizer.php","position":5,"original_position":5,"commit_id":"b29e2311c9b3f1a511f96406946116e3ba43fa5e","original_commit_id":"b29e2311c9b3f1a511f96406946116e3ba43fa5e","user":{"login":"LRotherfield","id":186184,"avatar_url":"https://avatars.githubusercontent.com/u/186184?v=3","gravatar_id":"","url":"https://api.github.com/users/LRotherfield","html_url":"https://github.com/LRotherfield","followers_url":"https://api.github.com/users/LRotherfield/followers","following_url":"https://api.github.com/users/LRotherfield/following{/other_user}","gists_url":"https://api.github.com/users/LRotherfield/gists{/gist_id}","starred_url":"https://api.github.com/users/LRotherfield/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/LRotherfield/subscriptions","organizations_url":"https://api.github.com/users/LRotherfield/orgs","repos_url":"https://api.github.com/users/LRotherfield/repos","events_url":"https://api.github.com/users/LRotherfield/events{/privacy}","received_events_url":"https://api.github.com/users/LRotherfield/received_events","type":"User","site_admin":false},"body":"I think I may be missing something as I don't see how this value could be a join or composite primary key because [here](https://github.com/LRotherfield/platform/blob/hotfix/datagrid-complex-join-pagination/src/Oro/Bundle/BatchBundle/ORM/QueryBuilder/CountQueryBuilderOptimizer.php#L185) you are making sure that only one field is returned as the primary id field?\r\n\r\nIf there is an issue then this code wont work because DISTINCT is key to this patch https://github.com/doctrine/doctrine2/blob/a41e774bb1f84d6f139438e40c45d54f042978c0/tests/Doctrine/Tests/ORM/Tools/Pagination/LimitSubqueryWalkerTest.php","created_at":"2015-03-12T09:56:46Z","updated_at":"2015-03-12T09:56:46Z","html_url":"https://github.com/orocrm/platform/pull/238#discussion_r26288985","pull_request_url":"https://api.github.com/repos/orocrm/platform/pulls/238","_links":{"self":{"href":"https://api.github.com/repos/orocrm/platform/pulls/comments/26288985"},"html":{"href":"https://github.com/orocrm/platform/pull/238#discussion_r26288985"},"pull_request":{"href":"https://api.github.com/repos/orocrm/platform/pulls/238"}}},"pull_request":{"url":"https://api.github.com/repos/orocrm/platform/pulls/238","id":30853099,"html_url":"https://github.com/orocrm/platform/pull/238","diff_url":"https://github.com/orocrm/platform/pull/238.diff","patch_url":"https://github.com/orocrm/platform/pull/238.patch","issue_url":"https://api.github.com/repos/orocrm/platform/issues/238","number":238,"state":"open","locked":false,"title":"Bug: Datagrids return the wrong number of rows when paginating a complex joined query","user":{"login":"LRotherfield","id":186184,"avatar_url":"https://avatars.githubusercontent.com/u/186184?v=3","gravatar_id":"","url":"https://api.github.com/users/LRotherfield","html_url":"https://github.com/LRotherfield","followers_url":"https://api.github.com/users/LRotherfield/followers","following_url":"https://api.github.com/users/LRotherfield/following{/other_user}","gists_url":"https://api.github.com/users/LRotherfield/gists{/gist_id}","starred_url":"https://api.github.com/users/LRotherfield/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/LRotherfield/subscriptions","organizations_url":"https://api.github.com/users/LRotherfield/orgs","repos_url":"https://api.github.com/users/LRotherfield/repos","events_url":"https://api.github.com/users/LRotherfield/events{/privacy}","received_events_url":"https://api.github.com/users/LRotherfield/received_events","type":"User","site_admin":false},"body":"Fix: For non grouped queries, paginate results using Doctrine Paginator methodolgy;\r\n  Perform a Count query using DISTINCT keyword.\r\n  Perform a Limit Subquery with DISTINCT to find all ids of the entity in from on the current page.\r\n  Perform a WHERE IN query to get all results for the current page.\r\n\r\nIncludes updated test scenarios for CountQueryBuilderOptimizer.\r\n\r\nI am happy to make any updates required, this works for all of the scenarios I have tested","created_at":"2015-03-10T14:10:52Z","updated_at":"2015-03-12T09:56:46Z","closed_at":null,"merged_at":null,"merge_commit_sha":"5734f5003aeab860ba563bd7fa819ffb38e26cc0","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/orocrm/platform/pulls/238/commits","review_comments_url":"https://api.github.com/repos/orocrm/platform/pulls/238/comments","review_comment_url":"https://api.github.com/repos/orocrm/platform/pulls/comments{/number}","comments_url":"https://api.github.com/repos/orocrm/platform/issues/238/comments","statuses_url":"https://api.github.com/repos/orocrm/platform/statuses/b29e2311c9b3f1a511f96406946116e3ba43fa5e","head":{"label":"LRotherfield:hotfix/datagrid-complex-join-pagination","ref":"hotfix/datagrid-complex-join-pagination","sha":"b29e2311c9b3f1a511f96406946116e3ba43fa5e","user":{"login":"LRotherfield","id":186184,"avatar_url":"https://avatars.githubusercontent.com/u/186184?v=3","gravatar_id":"","url":"https://api.github.com/users/LRotherfield","html_url":"https://github.com/LRotherfield","followers_url":"https://api.github.com/users/LRotherfield/followers","following_url":"https://api.github.com/users/LRotherfield/following{/other_user}","gists_url":"https://api.github.com/users/LRotherfield/gists{/gist_id}","starred_url":"https://api.github.com/users/LRotherfield/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/LRotherfield/subscriptions","organizations_url":"https://api.github.com/users/LRotherfield/orgs","repos_url":"https://api.github.com/users/LRotherfield/repos","events_url":"https://api.github.com/users/LRotherfield/events{/privacy}","received_events_url":"https://api.github.com/users/LRotherfield/received_events","type":"User","site_admin":false},"repo":{"id":23823965,"name":"platform","full_name":"LRotherfield/platform","owner":{"login":"LRotherfield","id":186184,"avatar_url":"https://avatars.githubusercontent.com/u/186184?v=3","gravatar_id":"","url":"https://api.github.com/users/LRotherfield","html_url":"https://github.com/LRotherfield","followers_url":"https://api.github.com/users/LRotherfield/followers","following_url":"https://api.github.com/users/LRotherfield/following{/other_user}","gists_url":"https://api.github.com/users/LRotherfield/gists{/gist_id}","starred_url":"https://api.github.com/users/LRotherfield/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/LRotherfield/subscriptions","organizations_url":"https://api.github.com/users/LRotherfield/orgs","repos_url":"https://api.github.com/users/LRotherfield/repos","events_url":"https://api.github.com/users/LRotherfield/events{/privacy}","received_events_url":"https://api.github.com/users/LRotherfield/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/LRotherfield/platform","description":"The Oro Platform - Business Application Platform (BAP)","fork":true,"url":"https://api.github.com/repos/LRotherfield/platform","forks_url":"https://api.github.com/repos/LRotherfield/platform/forks","keys_url":"https://api.github.com/repos/LRotherfield/platform/keys{/key_id}","collaborators_url":"https://api.github.com/repos/LRotherfield/platform/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/LRotherfield/platform/teams","hooks_url":"https://api.github.com/repos/LRotherfield/platform/hooks","issue_events_url":"https://api.github.com/repos/LRotherfield/platform/issues/events{/number}","events_url":"https://api.github.com/repos/LRotherfield/platform/events","assignees_url":"https://api.github.com/repos/LRotherfield/platform/assignees{/user}","branches_url":"https://api.github.com/repos/LRotherfield/platform/branches{/branch}","tags_url":"https://api.github.com/repos/LRotherfield/platform/tags","blobs_url":"https://api.github.com/repos/LRotherfield/platform/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/LRotherfield/platform/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/LRotherfield/platform/git/refs{/sha}","trees_url":"https://api.github.com/repos/LRotherfield/platform/git/trees{/sha}","statuses_url":"https://api.github.com/repos/LRotherfield/platform/statuses/{sha}","languages_url":"https://api.github.com/repos/LRotherfield/platform/languages","stargazers_url":"https://api.github.com/repos/LRotherfield/platform/stargazers","contributors_url":"https://api.github.com/repos/LRotherfield/platform/contributors","subscribers_url":"https://api.github.com/repos/LRotherfield/platform/subscribers","subscription_url":"https://api.github.com/repos/LRotherfield/platform/subscription","commits_url":"https://api.github.com/repos/LRotherfield/platform/commits{/sha}","git_commits_url":"https://api.github.com/repos/LRotherfield/platform/git/commits{/sha}","comments_url":"https://api.github.com/repos/LRotherfield/platform/comments{/number}","issue_comment_url":"https://api.github.com/repos/LRotherfield/platform/issues/comments{/number}","contents_url":"https://api.github.com/repos/LRotherfield/platform/contents/{+path}","compare_url":"https://api.github.com/repos/LRotherfield/platform/compare/{base}...{head}","merges_url":"https://api.github.com/repos/LRotherfield/platform/merges","archive_url":"https://api.github.com/repos/LRotherfield/platform/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/LRotherfield/platform/downloads","issues_url":"https://api.github.com/repos/LRotherfield/platform/issues{/number}","pulls_url":"https://api.github.com/repos/LRotherfield/platform/pulls{/number}","milestones_url":"https://api.github.com/repos/LRotherfield/platform/milestones{/number}","notifications_url":"https://api.github.com/repos/LRotherfield/platform/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/LRotherfield/platform/labels{/name}","releases_url":"https://api.github.com/repos/LRotherfield/platform/releases{/id}","created_at":"2014-09-09T07:35:39Z","updated_at":"2015-03-10T12:44:23Z","pushed_at":"2015-03-10T16:31:37Z","git_url":"git://github.com/LRotherfield/platform.git","ssh_url":"git@github.com:LRotherfield/platform.git","clone_url":"https://github.com/LRotherfield/platform.git","svn_url":"https://github.com/LRotherfield/platform","homepage":"","size":60726,"stargazers_count":0,"watchers_count":0,"language":"PHP","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"orocrm:master","ref":"master","sha":"59a1b59f58768ecf3da7d3f6731b16f22fd48ff2","user":{"login":"orocrm","id":4165718,"avatar_url":"https://avatars.githubusercontent.com/u/4165718?v=3","gravatar_id":"","url":"https://api.github.com/users/orocrm","html_url":"https://github.com/orocrm","followers_url":"https://api.github.com/users/orocrm/followers","following_url":"https://api.github.com/users/orocrm/following{/other_user}","gists_url":"https://api.github.com/users/orocrm/gists{/gist_id}","starred_url":"https://api.github.com/users/orocrm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/orocrm/subscriptions","organizations_url":"https://api.github.com/users/orocrm/orgs","repos_url":"https://api.github.com/users/orocrm/repos","events_url":"https://api.github.com/users/orocrm/events{/privacy}","received_events_url":"https://api.github.com/users/orocrm/received_events","type":"Organization","site_admin":false},"repo":{"id":10450961,"name":"platform","full_name":"orocrm/platform","owner":{"login":"orocrm","id":4165718,"avatar_url":"https://avatars.githubusercontent.com/u/4165718?v=3","gravatar_id":"","url":"https://api.github.com/users/orocrm","html_url":"https://github.com/orocrm","followers_url":"https://api.github.com/users/orocrm/followers","following_url":"https://api.github.com/users/orocrm/following{/other_user}","gists_url":"https://api.github.com/users/orocrm/gists{/gist_id}","starred_url":"https://api.github.com/users/orocrm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/orocrm/subscriptions","organizations_url":"https://api.github.com/users/orocrm/orgs","repos_url":"https://api.github.com/users/orocrm/repos","events_url":"https://api.github.com/users/orocrm/events{/privacy}","received_events_url":"https://api.github.com/users/orocrm/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/orocrm/platform","description":"The Oro Platform - Business Application Platform (BAP)","fork":false,"url":"https://api.github.com/repos/orocrm/platform","forks_url":"https://api.github.com/repos/orocrm/platform/forks","keys_url":"https://api.github.com/repos/orocrm/platform/keys{/key_id}","collaborators_url":"https://api.github.com/repos/orocrm/platform/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/orocrm/platform/teams","hooks_url":"https://api.github.com/repos/orocrm/platform/hooks","issue_events_url":"https://api.github.com/repos/orocrm/platform/issues/events{/number}","events_url":"https://api.github.com/repos/orocrm/platform/events","assignees_url":"https://api.github.com/repos/orocrm/platform/assignees{/user}","branches_url":"https://api.github.com/repos/orocrm/platform/branches{/branch}","tags_url":"https://api.github.com/repos/orocrm/platform/tags","blobs_url":"https://api.github.com/repos/orocrm/platform/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/orocrm/platform/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/orocrm/platform/git/refs{/sha}","trees_url":"https://api.github.com/repos/orocrm/platform/git/trees{/sha}","statuses_url":"https://api.github.com/repos/orocrm/platform/statuses/{sha}","languages_url":"https://api.github.com/repos/orocrm/platform/languages","stargazers_url":"https://api.github.com/repos/orocrm/platform/stargazers","contributors_url":"https://api.github.com/repos/orocrm/platform/contributors","subscribers_url":"https://api.github.com/repos/orocrm/platform/subscribers","subscription_url":"https://api.github.com/repos/orocrm/platform/subscription","commits_url":"https://api.github.com/repos/orocrm/platform/commits{/sha}","git_commits_url":"https://api.github.com/repos/orocrm/platform/git/commits{/sha}","comments_url":"https://api.github.com/repos/orocrm/platform/comments{/number}","issue_comment_url":"https://api.github.com/repos/orocrm/platform/issues/comments{/number}","contents_url":"https://api.github.com/repos/orocrm/platform/contents/{+path}","compare_url":"https://api.github.com/repos/orocrm/platform/compare/{base}...{head}","merges_url":"https://api.github.com/repos/orocrm/platform/merges","archive_url":"https://api.github.com/repos/orocrm/platform/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/orocrm/platform/downloads","issues_url":"https://api.github.com/repos/orocrm/platform/issues{/number}","pulls_url":"https://api.github.com/repos/orocrm/platform/pulls{/number}","milestones_url":"https://api.github.com/repos/orocrm/platform/milestones{/number}","notifications_url":"https://api.github.com/repos/orocrm/platform/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/orocrm/platform/labels{/name}","releases_url":"https://api.github.com/repos/orocrm/platform/releases{/id}","created_at":"2013-06-03T09:06:52Z","updated_at":"2015-03-12T06:25:48Z","pushed_at":"2015-03-12T06:25:47Z","git_url":"git://github.com/orocrm/platform.git","ssh_url":"git@github.com:orocrm/platform.git","clone_url":"https://github.com/orocrm/platform.git","svn_url":"https://github.com/orocrm/platform","homepage":"","size":64271,"stargazers_count":265,"watchers_count":265,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":108,"mirror_url":null,"open_issues_count":63,"forks":108,"open_issues":63,"watchers":265,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/orocrm/platform/pulls/238"},"html":{"href":"https://github.com/orocrm/platform/pull/238"},"issue":{"href":"https://api.github.com/repos/orocrm/platform/issues/238"},"comments":{"href":"https://api.github.com/repos/orocrm/platform/issues/238/comments"},"review_comments":{"href":"https://api.github.com/repos/orocrm/platform/pulls/238/comments"},"review_comment":{"href":"https://api.github.com/repos/orocrm/platform/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/orocrm/platform/pulls/238/commits"},"statuses":{"href":"https://api.github.com/repos/orocrm/platform/statuses/b29e2311c9b3f1a511f96406946116e3ba43fa5e"}}}}