{"action":"created","comment":{"url":"https://api.github.com/repos/gitlabhq/gitlabhq/pulls/comments/30970419","id":30970419,"diff_hunk":"@@ -7,15 +7,23 @@ namespace :gitlab do\n \n       projects = find_projects(namespace_path)\n \n+      with_hook_scope = ProjectHook.where(url: web_hook_url)\n+      with_hook_scope = with_hook_scope.where(project: projects) unless projects == Project # there is Rails bug","path":"lib/tasks/gitlab/web_hook.rake","position":5,"original_position":5,"commit_id":"b6f8b37e92a6a4ab3bc196c99fe9610bfe206c04","original_commit_id":"b6f8b37e92a6a4ab3bc196c99fe9610bfe206c04","user":{"login":"newmen","id":983853,"avatar_url":"https://avatars.githubusercontent.com/u/983853?v=3","gravatar_id":"","url":"https://api.github.com/users/newmen","html_url":"https://github.com/newmen","followers_url":"https://api.github.com/users/newmen/followers","following_url":"https://api.github.com/users/newmen/following{/other_user}","gists_url":"https://api.github.com/users/newmen/gists{/gist_id}","starred_url":"https://api.github.com/users/newmen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/newmen/subscriptions","organizations_url":"https://api.github.com/users/newmen/orgs","repos_url":"https://api.github.com/users/newmen/repos","events_url":"https://api.github.com/users/newmen/events{/privacy}","received_events_url":"https://api.github.com/users/newmen/received_events","type":"User","site_admin":false},"body":"The problem is:\r\n```\r\nLoading production environment (Rails 4.1.9)\r\nirb(main):001:0> ProjectHook.where(url: 'asdf', project: Project).to_sql\r\n=> \"SELECT \\\"web_hooks\\\".* FROM \\\"web_hooks\\\"  WHERE \\\"web_hooks\\\".\\\"type\\\" IN ('ProjectHook') AND \\\"web_hooks\\\".\\\"url\\\" = 'asdf' AND \\\"web_hooks\\\".\\\"project_id\\\" = 0  ORDER BY \\\"web_hooks\\\".\\\"created_at\\\" DESC, \\\"web_hooks\\\".\\\"id\\\" DESC\"\r\n```\r\nSo, when the `Project` isn't scoped then request contains incorrect condition.\r\nBut when we're use the scoped `Project` like:\r\n```\r\nirb(main):006:0> ProjectHook.where(url: 'asdf', project: Project.all.reorder('')).to_sql\r\n=> \"SELECT \\\"web_hooks\\\".* FROM \\\"web_hooks\\\"  WHERE \\\"web_hooks\\\".\\\"type\\\" IN ('ProjectHook') AND \\\"web_hooks\\\".\\\"url\\\" = 'asdf' AND \\\"web_hooks\\\".\\\"project_id\\\" IN (SELECT \\\"projects\\\".\\\"id\\\" FROM \\\"projects\\\")  ORDER BY \\\"web_hooks\\\".\\\"created_at\\\" DESC, \\\"web_hooks\\\".\\\"id\\\" DESC\"\r\n```\r\nthen resulting request is pretty correct.\r\n\r\nI can change the 11 line of my patch or can change the method which returns the unscoped `Project` for `Project.all.reorder('')`. How to do better?\r\n\r\nP.S. I don't know is it bug or not. But I think it is non-obvious behavior.","created_at":"2015-05-25T09:13:03Z","updated_at":"2015-05-25T09:13:03Z","html_url":"https://github.com/gitlabhq/gitlabhq/pull/9246#discussion_r30970419","pull_request_url":"https://api.github.com/repos/gitlabhq/gitlabhq/pulls/9246","_links":{"self":{"href":"https://api.github.com/repos/gitlabhq/gitlabhq/pulls/comments/30970419"},"html":{"href":"https://github.com/gitlabhq/gitlabhq/pull/9246#discussion_r30970419"},"pull_request":{"href":"https://api.github.com/repos/gitlabhq/gitlabhq/pulls/9246"}}},"pull_request":{"url":"https://api.github.com/repos/gitlabhq/gitlabhq/pulls/9246","id":34797128,"html_url":"https://github.com/gitlabhq/gitlabhq/pull/9246","diff_url":"https://github.com/gitlabhq/gitlabhq/pull/9246.diff","patch_url":"https://github.com/gitlabhq/gitlabhq/pull/9246.patch","issue_url":"https://api.github.com/repos/gitlabhq/gitlabhq/issues/9246","number":9246,"state":"open","locked":false,"title":"Skip adding hook by rake if one already added","user":{"login":"newmen","id":983853,"avatar_url":"https://avatars.githubusercontent.com/u/983853?v=3","gravatar_id":"","url":"https://api.github.com/users/newmen","html_url":"https://github.com/newmen","followers_url":"https://api.github.com/users/newmen/followers","following_url":"https://api.github.com/users/newmen/following{/other_user}","gists_url":"https://api.github.com/users/newmen/gists{/gist_id}","starred_url":"https://api.github.com/users/newmen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/newmen/subscriptions","organizations_url":"https://api.github.com/users/newmen/orgs","repos_url":"https://api.github.com/users/newmen/repos","events_url":"https://api.github.com/users/newmen/events{/privacy}","received_events_url":"https://api.github.com/users/newmen/received_events","type":"User","site_admin":false},"body":"Now we can run rake task without care about webhook duplication","created_at":"2015-05-06T08:32:16Z","updated_at":"2015-05-25T09:13:03Z","closed_at":null,"merged_at":null,"merge_commit_sha":"703b18071b0d740918315c88c0fb2062cf91ae65","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/gitlabhq/gitlabhq/pulls/9246/commits","review_comments_url":"https://api.github.com/repos/gitlabhq/gitlabhq/pulls/9246/comments","review_comment_url":"https://api.github.com/repos/gitlabhq/gitlabhq/pulls/comments{/number}","comments_url":"https://api.github.com/repos/gitlabhq/gitlabhq/issues/9246/comments","statuses_url":"https://api.github.com/repos/gitlabhq/gitlabhq/statuses/b6f8b37e92a6a4ab3bc196c99fe9610bfe206c04","head":{"label":"newmen:skip-adding-hook","ref":"skip-adding-hook","sha":"b6f8b37e92a6a4ab3bc196c99fe9610bfe206c04","user":{"login":"newmen","id":983853,"avatar_url":"https://avatars.githubusercontent.com/u/983853?v=3","gravatar_id":"","url":"https://api.github.com/users/newmen","html_url":"https://github.com/newmen","followers_url":"https://api.github.com/users/newmen/followers","following_url":"https://api.github.com/users/newmen/following{/other_user}","gists_url":"https://api.github.com/users/newmen/gists{/gist_id}","starred_url":"https://api.github.com/users/newmen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/newmen/subscriptions","organizations_url":"https://api.github.com/users/newmen/orgs","repos_url":"https://api.github.com/users/newmen/repos","events_url":"https://api.github.com/users/newmen/events{/privacy}","received_events_url":"https://api.github.com/users/newmen/received_events","type":"User","site_admin":false},"repo":{"id":35147187,"name":"gitlabhq","full_name":"newmen/gitlabhq","owner":{"login":"newmen","id":983853,"avatar_url":"https://avatars.githubusercontent.com/u/983853?v=3","gravatar_id":"","url":"https://api.github.com/users/newmen","html_url":"https://github.com/newmen","followers_url":"https://api.github.com/users/newmen/followers","following_url":"https://api.github.com/users/newmen/following{/other_user}","gists_url":"https://api.github.com/users/newmen/gists{/gist_id}","starred_url":"https://api.github.com/users/newmen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/newmen/subscriptions","organizations_url":"https://api.github.com/users/newmen/orgs","repos_url":"https://api.github.com/users/newmen/repos","events_url":"https://api.github.com/users/newmen/events{/privacy}","received_events_url":"https://api.github.com/users/newmen/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/newmen/gitlabhq","description":"GitLab is version control for your server","fork":true,"url":"https://api.github.com/repos/newmen/gitlabhq","forks_url":"https://api.github.com/repos/newmen/gitlabhq/forks","keys_url":"https://api.github.com/repos/newmen/gitlabhq/keys{/key_id}","collaborators_url":"https://api.github.com/repos/newmen/gitlabhq/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/newmen/gitlabhq/teams","hooks_url":"https://api.github.com/repos/newmen/gitlabhq/hooks","issue_events_url":"https://api.github.com/repos/newmen/gitlabhq/issues/events{/number}","events_url":"https://api.github.com/repos/newmen/gitlabhq/events","assignees_url":"https://api.github.com/repos/newmen/gitlabhq/assignees{/user}","branches_url":"https://api.github.com/repos/newmen/gitlabhq/branches{/branch}","tags_url":"https://api.github.com/repos/newmen/gitlabhq/tags","blobs_url":"https://api.github.com/repos/newmen/gitlabhq/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/newmen/gitlabhq/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/newmen/gitlabhq/git/refs{/sha}","trees_url":"https://api.github.com/repos/newmen/gitlabhq/git/trees{/sha}","statuses_url":"https://api.github.com/repos/newmen/gitlabhq/statuses/{sha}","languages_url":"https://api.github.com/repos/newmen/gitlabhq/languages","stargazers_url":"https://api.github.com/repos/newmen/gitlabhq/stargazers","contributors_url":"https://api.github.com/repos/newmen/gitlabhq/contributors","subscribers_url":"https://api.github.com/repos/newmen/gitlabhq/subscribers","subscription_url":"https://api.github.com/repos/newmen/gitlabhq/subscription","commits_url":"https://api.github.com/repos/newmen/gitlabhq/commits{/sha}","git_commits_url":"https://api.github.com/repos/newmen/gitlabhq/git/commits{/sha}","comments_url":"https://api.github.com/repos/newmen/gitlabhq/comments{/number}","issue_comment_url":"https://api.github.com/repos/newmen/gitlabhq/issues/comments{/number}","contents_url":"https://api.github.com/repos/newmen/gitlabhq/contents/{+path}","compare_url":"https://api.github.com/repos/newmen/gitlabhq/compare/{base}...{head}","merges_url":"https://api.github.com/repos/newmen/gitlabhq/merges","archive_url":"https://api.github.com/repos/newmen/gitlabhq/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/newmen/gitlabhq/downloads","issues_url":"https://api.github.com/repos/newmen/gitlabhq/issues{/number}","pulls_url":"https://api.github.com/repos/newmen/gitlabhq/pulls{/number}","milestones_url":"https://api.github.com/repos/newmen/gitlabhq/milestones{/number}","notifications_url":"https://api.github.com/repos/newmen/gitlabhq/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/newmen/gitlabhq/labels{/name}","releases_url":"https://api.github.com/repos/newmen/gitlabhq/releases{/id}","created_at":"2015-05-06T08:14:18Z","updated_at":"2015-05-06T08:14:26Z","pushed_at":"2015-05-09T08:21:31Z","git_url":"git://github.com/newmen/gitlabhq.git","ssh_url":"git@github.com:newmen/gitlabhq.git","clone_url":"https://github.com/newmen/gitlabhq.git","svn_url":"https://github.com/newmen/gitlabhq","homepage":"https://gitlab.com/gitlab-org/gitlab-ce/tree/master","size":94509,"stargazers_count":0,"watchers_count":0,"language":"Ruby","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":"gitlabhq:master","ref":"master","sha":"40c8295a24aace3210a8bc485f853d556a8bdc5c","user":{"login":"gitlabhq","id":1086321,"avatar_url":"https://avatars.githubusercontent.com/u/1086321?v=3","gravatar_id":"","url":"https://api.github.com/users/gitlabhq","html_url":"https://github.com/gitlabhq","followers_url":"https://api.github.com/users/gitlabhq/followers","following_url":"https://api.github.com/users/gitlabhq/following{/other_user}","gists_url":"https://api.github.com/users/gitlabhq/gists{/gist_id}","starred_url":"https://api.github.com/users/gitlabhq/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gitlabhq/subscriptions","organizations_url":"https://api.github.com/users/gitlabhq/orgs","repos_url":"https://api.github.com/users/gitlabhq/repos","events_url":"https://api.github.com/users/gitlabhq/events{/privacy}","received_events_url":"https://api.github.com/users/gitlabhq/received_events","type":"Organization","site_admin":false},"repo":{"id":2500088,"name":"gitlabhq","full_name":"gitlabhq/gitlabhq","owner":{"login":"gitlabhq","id":1086321,"avatar_url":"https://avatars.githubusercontent.com/u/1086321?v=3","gravatar_id":"","url":"https://api.github.com/users/gitlabhq","html_url":"https://github.com/gitlabhq","followers_url":"https://api.github.com/users/gitlabhq/followers","following_url":"https://api.github.com/users/gitlabhq/following{/other_user}","gists_url":"https://api.github.com/users/gitlabhq/gists{/gist_id}","starred_url":"https://api.github.com/users/gitlabhq/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gitlabhq/subscriptions","organizations_url":"https://api.github.com/users/gitlabhq/orgs","repos_url":"https://api.github.com/users/gitlabhq/repos","events_url":"https://api.github.com/users/gitlabhq/events{/privacy}","received_events_url":"https://api.github.com/users/gitlabhq/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/gitlabhq/gitlabhq","description":"GitLab is version control for your server","fork":false,"url":"https://api.github.com/repos/gitlabhq/gitlabhq","forks_url":"https://api.github.com/repos/gitlabhq/gitlabhq/forks","keys_url":"https://api.github.com/repos/gitlabhq/gitlabhq/keys{/key_id}","collaborators_url":"https://api.github.com/repos/gitlabhq/gitlabhq/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/gitlabhq/gitlabhq/teams","hooks_url":"https://api.github.com/repos/gitlabhq/gitlabhq/hooks","issue_events_url":"https://api.github.com/repos/gitlabhq/gitlabhq/issues/events{/number}","events_url":"https://api.github.com/repos/gitlabhq/gitlabhq/events","assignees_url":"https://api.github.com/repos/gitlabhq/gitlabhq/assignees{/user}","branches_url":"https://api.github.com/repos/gitlabhq/gitlabhq/branches{/branch}","tags_url":"https://api.github.com/repos/gitlabhq/gitlabhq/tags","blobs_url":"https://api.github.com/repos/gitlabhq/gitlabhq/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/gitlabhq/gitlabhq/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/gitlabhq/gitlabhq/git/refs{/sha}","trees_url":"https://api.github.com/repos/gitlabhq/gitlabhq/git/trees{/sha}","statuses_url":"https://api.github.com/repos/gitlabhq/gitlabhq/statuses/{sha}","languages_url":"https://api.github.com/repos/gitlabhq/gitlabhq/languages","stargazers_url":"https://api.github.com/repos/gitlabhq/gitlabhq/stargazers","contributors_url":"https://api.github.com/repos/gitlabhq/gitlabhq/contributors","subscribers_url":"https://api.github.com/repos/gitlabhq/gitlabhq/subscribers","subscription_url":"https://api.github.com/repos/gitlabhq/gitlabhq/subscription","commits_url":"https://api.github.com/repos/gitlabhq/gitlabhq/commits{/sha}","git_commits_url":"https://api.github.com/repos/gitlabhq/gitlabhq/git/commits{/sha}","comments_url":"https://api.github.com/repos/gitlabhq/gitlabhq/comments{/number}","issue_comment_url":"https://api.github.com/repos/gitlabhq/gitlabhq/issues/comments{/number}","contents_url":"https://api.github.com/repos/gitlabhq/gitlabhq/contents/{+path}","compare_url":"https://api.github.com/repos/gitlabhq/gitlabhq/compare/{base}...{head}","merges_url":"https://api.github.com/repos/gitlabhq/gitlabhq/merges","archive_url":"https://api.github.com/repos/gitlabhq/gitlabhq/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/gitlabhq/gitlabhq/downloads","issues_url":"https://api.github.com/repos/gitlabhq/gitlabhq/issues{/number}","pulls_url":"https://api.github.com/repos/gitlabhq/gitlabhq/pulls{/number}","milestones_url":"https://api.github.com/repos/gitlabhq/gitlabhq/milestones{/number}","notifications_url":"https://api.github.com/repos/gitlabhq/gitlabhq/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/gitlabhq/gitlabhq/labels{/name}","releases_url":"https://api.github.com/repos/gitlabhq/gitlabhq/releases{/id}","created_at":"2011-10-02T16:25:27Z","updated_at":"2015-05-25T08:32:51Z","pushed_at":"2015-05-24T05:52:04Z","git_url":"git://github.com/gitlabhq/gitlabhq.git","ssh_url":"git@github.com:gitlabhq/gitlabhq.git","clone_url":"https://github.com/gitlabhq/gitlabhq.git","svn_url":"https://github.com/gitlabhq/gitlabhq","homepage":"https://gitlab.com/gitlab-org/gitlab-ce/tree/master","size":171882,"stargazers_count":15582,"watchers_count":15582,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":4168,"mirror_url":null,"open_issues_count":666,"forks":4168,"open_issues":666,"watchers":15582,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/gitlabhq/gitlabhq/pulls/9246"},"html":{"href":"https://github.com/gitlabhq/gitlabhq/pull/9246"},"issue":{"href":"https://api.github.com/repos/gitlabhq/gitlabhq/issues/9246"},"comments":{"href":"https://api.github.com/repos/gitlabhq/gitlabhq/issues/9246/comments"},"review_comments":{"href":"https://api.github.com/repos/gitlabhq/gitlabhq/pulls/9246/comments"},"review_comment":{"href":"https://api.github.com/repos/gitlabhq/gitlabhq/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/gitlabhq/gitlabhq/pulls/9246/commits"},"statuses":{"href":"https://api.github.com/repos/gitlabhq/gitlabhq/statuses/b6f8b37e92a6a4ab3bc196c99fe9610bfe206c04"}}}}