{"action":"created","comment":{"url":"https://api.github.com/repos/stefankroes/ancestry/pulls/comments/242235310","pull_request_review_id":185699528,"id":242235310,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDI0MjIzNTMxMA==","diff_hunk":"@@ -17,6 +17,17 @@ def scope_depth depth_options, depth\n       end\n     end\n \n+    # Scope that returns all the leaves\n+    def leaves\n+      id_column = \"#{table_name}.id\"\n+      id_column_as_text = sql_cast_as_text(id_column)\n+      parent_ancestry = sql_concat(\"#{table_name}.#{ancestry_column}\", \"'/'\", id_column_as_text)\n+\n+      joins(\"LEFT JOIN #{table_name} AS c ON c.#{ancestry_column} = #{id_column_as_text} OR c.#{ancestry_column} = #{parent_ancestry}\").","path":"lib/ancestry/class_methods.rb","position":10,"original_position":10,"commit_id":"d7acb940dc66e8116e896d6b0f515c921ebcd621","original_commit_id":"d7acb940dc66e8116e896d6b0f515c921ebcd621","user":{"login":"kbrock","id":1930,"node_id":"MDQ6VXNlcjE5MzA=","avatar_url":"https://avatars2.githubusercontent.com/u/1930?v=4","gravatar_id":"","url":"https://api.github.com/users/kbrock","html_url":"https://github.com/kbrock","followers_url":"https://api.github.com/users/kbrock/followers","following_url":"https://api.github.com/users/kbrock/following{/other_user}","gists_url":"https://api.github.com/users/kbrock/gists{/gist_id}","starred_url":"https://api.github.com/users/kbrock/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kbrock/subscriptions","organizations_url":"https://api.github.com/users/kbrock/orgs","repos_url":"https://api.github.com/users/kbrock/repos","events_url":"https://api.github.com/users/kbrock/events{/privacy}","received_events_url":"https://api.github.com/users/kbrock/received_events","type":"User","site_admin":false},"body":"better yet, is there a way to extract this concept so we can use it more?","created_at":"2018-12-17T17:09:53Z","updated_at":"2018-12-17T17:09:54Z","html_url":"https://github.com/stefankroes/ancestry/pull/271#discussion_r242235310","pull_request_url":"https://api.github.com/repos/stefankroes/ancestry/pulls/271","author_association":"COLLABORATOR","_links":{"self":{"href":"https://api.github.com/repos/stefankroes/ancestry/pulls/comments/242235310"},"html":{"href":"https://github.com/stefankroes/ancestry/pull/271#discussion_r242235310"},"pull_request":{"href":"https://api.github.com/repos/stefankroes/ancestry/pulls/271"}},"in_reply_to_id":63056548},"pull_request":{"url":"https://api.github.com/repos/stefankroes/ancestry/pulls/271","id":62032330,"node_id":"MDExOlB1bGxSZXF1ZXN0NjIwMzIzMzA=","html_url":"https://github.com/stefankroes/ancestry/pull/271","diff_url":"https://github.com/stefankroes/ancestry/pull/271.diff","patch_url":"https://github.com/stefankroes/ancestry/pull/271.patch","issue_url":"https://api.github.com/repos/stefankroes/ancestry/issues/271","number":271,"state":"open","locked":false,"title":"Leave Scope Added","user":{"login":"ImDineshSaini","id":16646294,"node_id":"MDQ6VXNlcjE2NjQ2Mjk0","avatar_url":"https://avatars1.githubusercontent.com/u/16646294?v=4","gravatar_id":"","url":"https://api.github.com/users/ImDineshSaini","html_url":"https://github.com/ImDineshSaini","followers_url":"https://api.github.com/users/ImDineshSaini/followers","following_url":"https://api.github.com/users/ImDineshSaini/following{/other_user}","gists_url":"https://api.github.com/users/ImDineshSaini/gists{/gist_id}","starred_url":"https://api.github.com/users/ImDineshSaini/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ImDineshSaini/subscriptions","organizations_url":"https://api.github.com/users/ImDineshSaini/orgs","repos_url":"https://api.github.com/users/ImDineshSaini/repos","events_url":"https://api.github.com/users/ImDineshSaini/events{/privacy}","received_events_url":"https://api.github.com/users/ImDineshSaini/received_events","type":"User","site_admin":false},"body":"Leave scope added and now the function can be used as ModelName.leaves\n","created_at":"2016-03-08T06:57:01Z","updated_at":"2018-12-17T17:09:53Z","closed_at":null,"merged_at":null,"merge_commit_sha":"5f1f607f85077033b67344c7345f5f9af2d97a5c","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/stefankroes/ancestry/pulls/271/commits","review_comments_url":"https://api.github.com/repos/stefankroes/ancestry/pulls/271/comments","review_comment_url":"https://api.github.com/repos/stefankroes/ancestry/pulls/comments{/number}","comments_url":"https://api.github.com/repos/stefankroes/ancestry/issues/271/comments","statuses_url":"https://api.github.com/repos/stefankroes/ancestry/statuses/d7acb940dc66e8116e896d6b0f515c921ebcd621","head":{"label":"ImDineshSaini:master","ref":"master","sha":"d7acb940dc66e8116e896d6b0f515c921ebcd621","user":{"login":"ImDineshSaini","id":16646294,"node_id":"MDQ6VXNlcjE2NjQ2Mjk0","avatar_url":"https://avatars1.githubusercontent.com/u/16646294?v=4","gravatar_id":"","url":"https://api.github.com/users/ImDineshSaini","html_url":"https://github.com/ImDineshSaini","followers_url":"https://api.github.com/users/ImDineshSaini/followers","following_url":"https://api.github.com/users/ImDineshSaini/following{/other_user}","gists_url":"https://api.github.com/users/ImDineshSaini/gists{/gist_id}","starred_url":"https://api.github.com/users/ImDineshSaini/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ImDineshSaini/subscriptions","organizations_url":"https://api.github.com/users/ImDineshSaini/orgs","repos_url":"https://api.github.com/users/ImDineshSaini/repos","events_url":"https://api.github.com/users/ImDineshSaini/events{/privacy}","received_events_url":"https://api.github.com/users/ImDineshSaini/received_events","type":"User","site_admin":false},"repo":null},"base":{"label":"stefankroes:master","ref":"master","sha":"e686dd14fb4d4d62d254a1d18bd35973e90d1280","user":{"login":"stefankroes","id":37841,"node_id":"MDQ6VXNlcjM3ODQx","avatar_url":"https://avatars3.githubusercontent.com/u/37841?v=4","gravatar_id":"","url":"https://api.github.com/users/stefankroes","html_url":"https://github.com/stefankroes","followers_url":"https://api.github.com/users/stefankroes/followers","following_url":"https://api.github.com/users/stefankroes/following{/other_user}","gists_url":"https://api.github.com/users/stefankroes/gists{/gist_id}","starred_url":"https://api.github.com/users/stefankroes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stefankroes/subscriptions","organizations_url":"https://api.github.com/users/stefankroes/orgs","repos_url":"https://api.github.com/users/stefankroes/repos","events_url":"https://api.github.com/users/stefankroes/events{/privacy}","received_events_url":"https://api.github.com/users/stefankroes/received_events","type":"User","site_admin":false},"repo":{"id":339567,"node_id":"MDEwOlJlcG9zaXRvcnkzMzk1Njc=","name":"ancestry","full_name":"stefankroes/ancestry","private":false,"owner":{"login":"stefankroes","id":37841,"node_id":"MDQ6VXNlcjM3ODQx","avatar_url":"https://avatars3.githubusercontent.com/u/37841?v=4","gravatar_id":"","url":"https://api.github.com/users/stefankroes","html_url":"https://github.com/stefankroes","followers_url":"https://api.github.com/users/stefankroes/followers","following_url":"https://api.github.com/users/stefankroes/following{/other_user}","gists_url":"https://api.github.com/users/stefankroes/gists{/gist_id}","starred_url":"https://api.github.com/users/stefankroes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stefankroes/subscriptions","organizations_url":"https://api.github.com/users/stefankroes/orgs","repos_url":"https://api.github.com/users/stefankroes/repos","events_url":"https://api.github.com/users/stefankroes/events{/privacy}","received_events_url":"https://api.github.com/users/stefankroes/received_events","type":"User","site_admin":false},"html_url":"https://github.com/stefankroes/ancestry","description":"Organise ActiveRecord model into a tree structure","fork":false,"url":"https://api.github.com/repos/stefankroes/ancestry","forks_url":"https://api.github.com/repos/stefankroes/ancestry/forks","keys_url":"https://api.github.com/repos/stefankroes/ancestry/keys{/key_id}","collaborators_url":"https://api.github.com/repos/stefankroes/ancestry/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/stefankroes/ancestry/teams","hooks_url":"https://api.github.com/repos/stefankroes/ancestry/hooks","issue_events_url":"https://api.github.com/repos/stefankroes/ancestry/issues/events{/number}","events_url":"https://api.github.com/repos/stefankroes/ancestry/events","assignees_url":"https://api.github.com/repos/stefankroes/ancestry/assignees{/user}","branches_url":"https://api.github.com/repos/stefankroes/ancestry/branches{/branch}","tags_url":"https://api.github.com/repos/stefankroes/ancestry/tags","blobs_url":"https://api.github.com/repos/stefankroes/ancestry/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/stefankroes/ancestry/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/stefankroes/ancestry/git/refs{/sha}","trees_url":"https://api.github.com/repos/stefankroes/ancestry/git/trees{/sha}","statuses_url":"https://api.github.com/repos/stefankroes/ancestry/statuses/{sha}","languages_url":"https://api.github.com/repos/stefankroes/ancestry/languages","stargazers_url":"https://api.github.com/repos/stefankroes/ancestry/stargazers","contributors_url":"https://api.github.com/repos/stefankroes/ancestry/contributors","subscribers_url":"https://api.github.com/repos/stefankroes/ancestry/subscribers","subscription_url":"https://api.github.com/repos/stefankroes/ancestry/subscription","commits_url":"https://api.github.com/repos/stefankroes/ancestry/commits{/sha}","git_commits_url":"https://api.github.com/repos/stefankroes/ancestry/git/commits{/sha}","comments_url":"https://api.github.com/repos/stefankroes/ancestry/comments{/number}","issue_comment_url":"https://api.github.com/repos/stefankroes/ancestry/issues/comments{/number}","contents_url":"https://api.github.com/repos/stefankroes/ancestry/contents/{+path}","compare_url":"https://api.github.com/repos/stefankroes/ancestry/compare/{base}...{head}","merges_url":"https://api.github.com/repos/stefankroes/ancestry/merges","archive_url":"https://api.github.com/repos/stefankroes/ancestry/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/stefankroes/ancestry/downloads","issues_url":"https://api.github.com/repos/stefankroes/ancestry/issues{/number}","pulls_url":"https://api.github.com/repos/stefankroes/ancestry/pulls{/number}","milestones_url":"https://api.github.com/repos/stefankroes/ancestry/milestones{/number}","notifications_url":"https://api.github.com/repos/stefankroes/ancestry/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/stefankroes/ancestry/labels{/name}","releases_url":"https://api.github.com/repos/stefankroes/ancestry/releases{/id}","deployments_url":"https://api.github.com/repos/stefankroes/ancestry/deployments","created_at":"2009-10-16T13:37:09Z","updated_at":"2018-12-12T09:42:24Z","pushed_at":"2018-11-14T12:45:42Z","git_url":"git://github.com/stefankroes/ancestry.git","ssh_url":"git@github.com:stefankroes/ancestry.git","clone_url":"https://github.com/stefankroes/ancestry.git","svn_url":"https://github.com/stefankroes/ancestry","homepage":"","size":8835,"stargazers_count":2758,"watchers_count":2758,"language":"Ruby","has_issues":true,"has_projects":true,"has_downloads":false,"has_wiki":true,"has_pages":true,"forks_count":391,"mirror_url":null,"archived":false,"open_issues_count":82,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":391,"open_issues":82,"watchers":2758,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/stefankroes/ancestry/pulls/271"},"html":{"href":"https://github.com/stefankroes/ancestry/pull/271"},"issue":{"href":"https://api.github.com/repos/stefankroes/ancestry/issues/271"},"comments":{"href":"https://api.github.com/repos/stefankroes/ancestry/issues/271/comments"},"review_comments":{"href":"https://api.github.com/repos/stefankroes/ancestry/pulls/271/comments"},"review_comment":{"href":"https://api.github.com/repos/stefankroes/ancestry/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/stefankroes/ancestry/pulls/271/commits"},"statuses":{"href":"https://api.github.com/repos/stefankroes/ancestry/statuses/d7acb940dc66e8116e896d6b0f515c921ebcd621"}},"author_association":"NONE"}}
{"actor":{"display_login":"kbrock"}}