{"action":"created","comment":{"url":"https://api.github.com/repos/andycroll/andycroll.com/pulls/comments/167405301","pull_request_review_id":95628215,"id":167405301,"diff_hunk":"@@ -0,0 +1,74 @@\n+---\n+title: 'Avoid Writing SQL When Using ActiveRelation'\n+description: 'It's fine, but prefer not to if you can.'\n+layout: article\n+category: ruby\n+image:\n+  base: '2018/avoid-writing-sql-when-using-activerelation'\n+  alt: 'Coding SQL'\n+  source: 'https://unsplash.com/photos/fPkvU7RDmCo'\n+  credit: 'Caspar Rubin'\n+---\n+\n+ActiveRelation, which powers the searching and querying engine of ActiveRecord, is a powerful and flexible tool.\n+\n+\n+## Instead of...\n+\n+...writing literal SQL strings inside an ActiveRelation `#where` method.\n+\n+```ruby\n+Person.where(\"name = #{ params[:name] } and hidden_at is null\")\n+```\n+\n+\n+## Or...\n+\n+...writing literal strings and using the Array method to sanitise data.\n+\n+```ruby","path":"_posts/2018/2018-02-18-avoid-writing-sql-when-using-activerelation.md","position":29,"original_position":29,"commit_id":"48d83eedc8051f90b43b184d02ebff88e6c5d1df","original_commit_id":"48d83eedc8051f90b43b184d02ebff88e6c5d1df","user":{"login":"andycroll","id":2780,"avatar_url":"https://avatars3.githubusercontent.com/u/2780?v=4","gravatar_id":"","url":"https://api.github.com/users/andycroll","html_url":"https://github.com/andycroll","followers_url":"https://api.github.com/users/andycroll/followers","following_url":"https://api.github.com/users/andycroll/following{/other_user}","gists_url":"https://api.github.com/users/andycroll/gists{/gist_id}","starred_url":"https://api.github.com/users/andycroll/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andycroll/subscriptions","organizations_url":"https://api.github.com/users/andycroll/orgs","repos_url":"https://api.github.com/users/andycroll/repos","events_url":"https://api.github.com/users/andycroll/events{/privacy}","received_events_url":"https://api.github.com/users/andycroll/received_events","type":"User","site_admin":false},"body":"You mean a `String` right?","created_at":"2018-02-10T17:34:27Z","updated_at":"2018-02-10T17:34:27Z","html_url":"https://github.com/andycroll/andycroll.com/pull/13#discussion_r167405301","pull_request_url":"https://api.github.com/repos/andycroll/andycroll.com/pulls/13","author_association":"OWNER","_links":{"self":{"href":"https://api.github.com/repos/andycroll/andycroll.com/pulls/comments/167405301"},"html":{"href":"https://github.com/andycroll/andycroll.com/pull/13#discussion_r167405301"},"pull_request":{"href":"https://api.github.com/repos/andycroll/andycroll.com/pulls/13"}},"in_reply_to_id":167392768},"pull_request":{"url":"https://api.github.com/repos/andycroll/andycroll.com/pulls/13","id":168193067,"html_url":"https://github.com/andycroll/andycroll.com/pull/13","diff_url":"https://github.com/andycroll/andycroll.com/pull/13.diff","patch_url":"https://github.com/andycroll/andycroll.com/pull/13.patch","issue_url":"https://api.github.com/repos/andycroll/andycroll.com/issues/13","number":13,"state":"open","locked":false,"title":"Avoid writing SQL in where clauses","user":{"login":"andycroll","id":2780,"avatar_url":"https://avatars3.githubusercontent.com/u/2780?v=4","gravatar_id":"","url":"https://api.github.com/users/andycroll","html_url":"https://github.com/andycroll","followers_url":"https://api.github.com/users/andycroll/followers","following_url":"https://api.github.com/users/andycroll/following{/other_user}","gists_url":"https://api.github.com/users/andycroll/gists{/gist_id}","starred_url":"https://api.github.com/users/andycroll/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andycroll/subscriptions","organizations_url":"https://api.github.com/users/andycroll/orgs","repos_url":"https://api.github.com/users/andycroll/repos","events_url":"https://api.github.com/users/andycroll/events{/privacy}","received_events_url":"https://api.github.com/users/andycroll/received_events","type":"User","site_admin":false},"body":"ActiveRecord-y fun.","created_at":"2018-02-09T09:42:19Z","updated_at":"2018-02-10T17:34:27Z","closed_at":null,"merged_at":null,"merge_commit_sha":"07358f4d618072829ab75d0c6980136743cc2a6d","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/andycroll/andycroll.com/pulls/13/commits","review_comments_url":"https://api.github.com/repos/andycroll/andycroll.com/pulls/13/comments","review_comment_url":"https://api.github.com/repos/andycroll/andycroll.com/pulls/comments{/number}","comments_url":"https://api.github.com/repos/andycroll/andycroll.com/issues/13/comments","statuses_url":"https://api.github.com/repos/andycroll/andycroll.com/statuses/48d83eedc8051f90b43b184d02ebff88e6c5d1df","head":{"label":"andycroll:no-sql-activerecord","ref":"no-sql-activerecord","sha":"48d83eedc8051f90b43b184d02ebff88e6c5d1df","user":{"login":"andycroll","id":2780,"avatar_url":"https://avatars3.githubusercontent.com/u/2780?v=4","gravatar_id":"","url":"https://api.github.com/users/andycroll","html_url":"https://github.com/andycroll","followers_url":"https://api.github.com/users/andycroll/followers","following_url":"https://api.github.com/users/andycroll/following{/other_user}","gists_url":"https://api.github.com/users/andycroll/gists{/gist_id}","starred_url":"https://api.github.com/users/andycroll/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andycroll/subscriptions","organizations_url":"https://api.github.com/users/andycroll/orgs","repos_url":"https://api.github.com/users/andycroll/repos","events_url":"https://api.github.com/users/andycroll/events{/privacy}","received_events_url":"https://api.github.com/users/andycroll/received_events","type":"User","site_admin":false},"repo":{"id":69390167,"name":"andycroll.com","full_name":"andycroll/andycroll.com","owner":{"login":"andycroll","id":2780,"avatar_url":"https://avatars3.githubusercontent.com/u/2780?v=4","gravatar_id":"","url":"https://api.github.com/users/andycroll","html_url":"https://github.com/andycroll","followers_url":"https://api.github.com/users/andycroll/followers","following_url":"https://api.github.com/users/andycroll/following{/other_user}","gists_url":"https://api.github.com/users/andycroll/gists{/gist_id}","starred_url":"https://api.github.com/users/andycroll/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andycroll/subscriptions","organizations_url":"https://api.github.com/users/andycroll/orgs","repos_url":"https://api.github.com/users/andycroll/repos","events_url":"https://api.github.com/users/andycroll/events{/privacy}","received_events_url":"https://api.github.com/users/andycroll/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/andycroll/andycroll.com","description":null,"fork":false,"url":"https://api.github.com/repos/andycroll/andycroll.com","forks_url":"https://api.github.com/repos/andycroll/andycroll.com/forks","keys_url":"https://api.github.com/repos/andycroll/andycroll.com/keys{/key_id}","collaborators_url":"https://api.github.com/repos/andycroll/andycroll.com/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/andycroll/andycroll.com/teams","hooks_url":"https://api.github.com/repos/andycroll/andycroll.com/hooks","issue_events_url":"https://api.github.com/repos/andycroll/andycroll.com/issues/events{/number}","events_url":"https://api.github.com/repos/andycroll/andycroll.com/events","assignees_url":"https://api.github.com/repos/andycroll/andycroll.com/assignees{/user}","branches_url":"https://api.github.com/repos/andycroll/andycroll.com/branches{/branch}","tags_url":"https://api.github.com/repos/andycroll/andycroll.com/tags","blobs_url":"https://api.github.com/repos/andycroll/andycroll.com/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/andycroll/andycroll.com/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/andycroll/andycroll.com/git/refs{/sha}","trees_url":"https://api.github.com/repos/andycroll/andycroll.com/git/trees{/sha}","statuses_url":"https://api.github.com/repos/andycroll/andycroll.com/statuses/{sha}","languages_url":"https://api.github.com/repos/andycroll/andycroll.com/languages","stargazers_url":"https://api.github.com/repos/andycroll/andycroll.com/stargazers","contributors_url":"https://api.github.com/repos/andycroll/andycroll.com/contributors","subscribers_url":"https://api.github.com/repos/andycroll/andycroll.com/subscribers","subscription_url":"https://api.github.com/repos/andycroll/andycroll.com/subscription","commits_url":"https://api.github.com/repos/andycroll/andycroll.com/commits{/sha}","git_commits_url":"https://api.github.com/repos/andycroll/andycroll.com/git/commits{/sha}","comments_url":"https://api.github.com/repos/andycroll/andycroll.com/comments{/number}","issue_comment_url":"https://api.github.com/repos/andycroll/andycroll.com/issues/comments{/number}","contents_url":"https://api.github.com/repos/andycroll/andycroll.com/contents/{+path}","compare_url":"https://api.github.com/repos/andycroll/andycroll.com/compare/{base}...{head}","merges_url":"https://api.github.com/repos/andycroll/andycroll.com/merges","archive_url":"https://api.github.com/repos/andycroll/andycroll.com/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/andycroll/andycroll.com/downloads","issues_url":"https://api.github.com/repos/andycroll/andycroll.com/issues{/number}","pulls_url":"https://api.github.com/repos/andycroll/andycroll.com/pulls{/number}","milestones_url":"https://api.github.com/repos/andycroll/andycroll.com/milestones{/number}","notifications_url":"https://api.github.com/repos/andycroll/andycroll.com/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/andycroll/andycroll.com/labels{/name}","releases_url":"https://api.github.com/repos/andycroll/andycroll.com/releases{/id}","deployments_url":"https://api.github.com/repos/andycroll/andycroll.com/deployments","created_at":"2016-09-27T19:15:14Z","updated_at":"2017-10-02T15:07:04Z","pushed_at":"2018-02-10T16:14:00Z","git_url":"git://github.com/andycroll/andycroll.com.git","ssh_url":"git@github.com:andycroll/andycroll.com.git","clone_url":"https://github.com/andycroll/andycroll.com.git","svn_url":"https://github.com/andycroll/andycroll.com","homepage":null,"size":31196,"stargazers_count":0,"watchers_count":0,"language":"HTML","has_issues":false,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1,"mirror_url":null,"archived":false,"open_issues_count":2,"license":null,"forks":1,"open_issues":2,"watchers":0,"default_branch":"master"}},"base":{"label":"andycroll:master","ref":"master","sha":"41136e7fdc6d94e7c5a956af6a88e143add62a2c","user":{"login":"andycroll","id":2780,"avatar_url":"https://avatars3.githubusercontent.com/u/2780?v=4","gravatar_id":"","url":"https://api.github.com/users/andycroll","html_url":"https://github.com/andycroll","followers_url":"https://api.github.com/users/andycroll/followers","following_url":"https://api.github.com/users/andycroll/following{/other_user}","gists_url":"https://api.github.com/users/andycroll/gists{/gist_id}","starred_url":"https://api.github.com/users/andycroll/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andycroll/subscriptions","organizations_url":"https://api.github.com/users/andycroll/orgs","repos_url":"https://api.github.com/users/andycroll/repos","events_url":"https://api.github.com/users/andycroll/events{/privacy}","received_events_url":"https://api.github.com/users/andycroll/received_events","type":"User","site_admin":false},"repo":{"id":69390167,"name":"andycroll.com","full_name":"andycroll/andycroll.com","owner":{"login":"andycroll","id":2780,"avatar_url":"https://avatars3.githubusercontent.com/u/2780?v=4","gravatar_id":"","url":"https://api.github.com/users/andycroll","html_url":"https://github.com/andycroll","followers_url":"https://api.github.com/users/andycroll/followers","following_url":"https://api.github.com/users/andycroll/following{/other_user}","gists_url":"https://api.github.com/users/andycroll/gists{/gist_id}","starred_url":"https://api.github.com/users/andycroll/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andycroll/subscriptions","organizations_url":"https://api.github.com/users/andycroll/orgs","repos_url":"https://api.github.com/users/andycroll/repos","events_url":"https://api.github.com/users/andycroll/events{/privacy}","received_events_url":"https://api.github.com/users/andycroll/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/andycroll/andycroll.com","description":null,"fork":false,"url":"https://api.github.com/repos/andycroll/andycroll.com","forks_url":"https://api.github.com/repos/andycroll/andycroll.com/forks","keys_url":"https://api.github.com/repos/andycroll/andycroll.com/keys{/key_id}","collaborators_url":"https://api.github.com/repos/andycroll/andycroll.com/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/andycroll/andycroll.com/teams","hooks_url":"https://api.github.com/repos/andycroll/andycroll.com/hooks","issue_events_url":"https://api.github.com/repos/andycroll/andycroll.com/issues/events{/number}","events_url":"https://api.github.com/repos/andycroll/andycroll.com/events","assignees_url":"https://api.github.com/repos/andycroll/andycroll.com/assignees{/user}","branches_url":"https://api.github.com/repos/andycroll/andycroll.com/branches{/branch}","tags_url":"https://api.github.com/repos/andycroll/andycroll.com/tags","blobs_url":"https://api.github.com/repos/andycroll/andycroll.com/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/andycroll/andycroll.com/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/andycroll/andycroll.com/git/refs{/sha}","trees_url":"https://api.github.com/repos/andycroll/andycroll.com/git/trees{/sha}","statuses_url":"https://api.github.com/repos/andycroll/andycroll.com/statuses/{sha}","languages_url":"https://api.github.com/repos/andycroll/andycroll.com/languages","stargazers_url":"https://api.github.com/repos/andycroll/andycroll.com/stargazers","contributors_url":"https://api.github.com/repos/andycroll/andycroll.com/contributors","subscribers_url":"https://api.github.com/repos/andycroll/andycroll.com/subscribers","subscription_url":"https://api.github.com/repos/andycroll/andycroll.com/subscription","commits_url":"https://api.github.com/repos/andycroll/andycroll.com/commits{/sha}","git_commits_url":"https://api.github.com/repos/andycroll/andycroll.com/git/commits{/sha}","comments_url":"https://api.github.com/repos/andycroll/andycroll.com/comments{/number}","issue_comment_url":"https://api.github.com/repos/andycroll/andycroll.com/issues/comments{/number}","contents_url":"https://api.github.com/repos/andycroll/andycroll.com/contents/{+path}","compare_url":"https://api.github.com/repos/andycroll/andycroll.com/compare/{base}...{head}","merges_url":"https://api.github.com/repos/andycroll/andycroll.com/merges","archive_url":"https://api.github.com/repos/andycroll/andycroll.com/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/andycroll/andycroll.com/downloads","issues_url":"https://api.github.com/repos/andycroll/andycroll.com/issues{/number}","pulls_url":"https://api.github.com/repos/andycroll/andycroll.com/pulls{/number}","milestones_url":"https://api.github.com/repos/andycroll/andycroll.com/milestones{/number}","notifications_url":"https://api.github.com/repos/andycroll/andycroll.com/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/andycroll/andycroll.com/labels{/name}","releases_url":"https://api.github.com/repos/andycroll/andycroll.com/releases{/id}","deployments_url":"https://api.github.com/repos/andycroll/andycroll.com/deployments","created_at":"2016-09-27T19:15:14Z","updated_at":"2017-10-02T15:07:04Z","pushed_at":"2018-02-10T16:14:00Z","git_url":"git://github.com/andycroll/andycroll.com.git","ssh_url":"git@github.com:andycroll/andycroll.com.git","clone_url":"https://github.com/andycroll/andycroll.com.git","svn_url":"https://github.com/andycroll/andycroll.com","homepage":null,"size":31196,"stargazers_count":0,"watchers_count":0,"language":"HTML","has_issues":false,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1,"mirror_url":null,"archived":false,"open_issues_count":2,"license":null,"forks":1,"open_issues":2,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/andycroll/andycroll.com/pulls/13"},"html":{"href":"https://github.com/andycroll/andycroll.com/pull/13"},"issue":{"href":"https://api.github.com/repos/andycroll/andycroll.com/issues/13"},"comments":{"href":"https://api.github.com/repos/andycroll/andycroll.com/issues/13/comments"},"review_comments":{"href":"https://api.github.com/repos/andycroll/andycroll.com/pulls/13/comments"},"review_comment":{"href":"https://api.github.com/repos/andycroll/andycroll.com/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/andycroll/andycroll.com/pulls/13/commits"},"statuses":{"href":"https://api.github.com/repos/andycroll/andycroll.com/statuses/48d83eedc8051f90b43b184d02ebff88e6c5d1df"}},"author_association":"OWNER"}}
{"actor":{"display_login":"andycroll"}}