{"action":"created","comment":{"url":"https://api.github.com/repos/rails/rails/pulls/comments/165225395","pull_request_review_id":93128738,"id":165225395,"diff_hunk":"@@ -94,12 +94,21 @@ def method_missing(method, *args, &block)\n \n     module ClassMethods # :nodoc:\n       def create(klass, *args)\n-        relation_class_for(klass).new(klass, *args)\n+        relation_class_for(klass, *args).new(klass, *args)\n       end\n \n       private\n \n-        def relation_class_for(klass)\n+        def relation_class_for(klass, *args)\n+          if args.first.is_a?(Associations::Association) && !klass.respond_to?(:relation_delegate_class)","path":"activerecord/lib/active_record/relation/delegation.rb","position":null,"original_position":12,"commit_id":"682f73e48e949d67cae338825bcdde4d60e260f0","original_commit_id":"e17118345c3cfb881ecbffb93c235f12426789a0","user":{"login":"composerinteralia","id":13696143,"avatar_url":"https://avatars3.githubusercontent.com/u/13696143?v=4","gravatar_id":"","url":"https://api.github.com/users/composerinteralia","html_url":"https://github.com/composerinteralia","followers_url":"https://api.github.com/users/composerinteralia/followers","following_url":"https://api.github.com/users/composerinteralia/following{/other_user}","gists_url":"https://api.github.com/users/composerinteralia/gists{/gist_id}","starred_url":"https://api.github.com/users/composerinteralia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/composerinteralia/subscriptions","organizations_url":"https://api.github.com/users/composerinteralia/orgs","repos_url":"https://api.github.com/users/composerinteralia/repos","events_url":"https://api.github.com/users/composerinteralia/events{/privacy}","received_events_url":"https://api.github.com/users/composerinteralia/received_events","type":"User","site_admin":false},"body":"I'm pretty new to this as well; sorry if I led you astray!","created_at":"2018-02-01T00:00:39Z","updated_at":"2018-02-01T00:00:39Z","html_url":"https://github.com/rails/rails/pull/31829#discussion_r165225395","pull_request_url":"https://api.github.com/repos/rails/rails/pulls/31829","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/rails/rails/pulls/comments/165225395"},"html":{"href":"https://github.com/rails/rails/pull/31829#discussion_r165225395"},"pull_request":{"href":"https://api.github.com/repos/rails/rails/pulls/31829"}},"in_reply_to_id":164940493},"pull_request":{"url":"https://api.github.com/repos/rails/rails/pulls/31829","id":166087955,"html_url":"https://github.com/rails/rails/pull/31829","diff_url":"https://github.com/rails/rails/pull/31829.diff","patch_url":"https://github.com/rails/rails/pull/31829.patch","issue_url":"https://api.github.com/repos/rails/rails/issues/31829","number":31829,"state":"open","locked":false,"title":"Improve the error (message) for associations to an invalid class","user":{"login":"saveriomiroddi","id":1595356,"avatar_url":"https://avatars2.githubusercontent.com/u/1595356?v=4","gravatar_id":"","url":"https://api.github.com/users/saveriomiroddi","html_url":"https://github.com/saveriomiroddi","followers_url":"https://api.github.com/users/saveriomiroddi/followers","following_url":"https://api.github.com/users/saveriomiroddi/following{/other_user}","gists_url":"https://api.github.com/users/saveriomiroddi/gists{/gist_id}","starred_url":"https://api.github.com/users/saveriomiroddi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/saveriomiroddi/subscriptions","organizations_url":"https://api.github.com/users/saveriomiroddi/orgs","repos_url":"https://api.github.com/users/saveriomiroddi/repos","events_url":"https://api.github.com/users/saveriomiroddi/events{/privacy}","received_events_url":"https://api.github.com/users/saveriomiroddi/received_events","type":"User","site_admin":false},"body":"If a user defines an association to an invalid class/module, eg.:\r\n\r\n    class Comment::Base < ActiveRecord::Base; end\r\n    class Post < ActiveRecord::Base; has_many :comments; end\r\n\r\nwith `Comment` not being a valid model (in this case, it's a module), on access, the error message will be correct but\r\ncryptic:\r\n\r\n    Post.comments # => \"undefined method `relation_delegate_class' for Comment:Module\"\r\n\r\nWith this change, the relation will be examined before, and if it doesn't\r\nsupport the expected method, it will raise a friendlier message:\r\n\r\n    Rails could not find a valid model for the :comments association.\r\n    Please provide the :class_name option on the association declaration\r\n\r\nCloses #15811.\r\n\r\nReview summary:\r\n\r\n- [x] move test class PlainKlass location inside file\r\n- [x] better String API usage for error message in Delegation#relation_class_for\r\n- [ ] :relation_delegate_class check location (and move the UT)\r\n  - posted analysis; it seems not trivial - requires review\r\n- [ ] check against the module or the method\r\n- [ ] solve conflict","created_at":"2018-01-30T20:23:44Z","updated_at":"2018-02-01T00:00:39Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c81ab7c597801503cf267dce3115e9dd1158bccc","assignee":{"login":"kamipo","id":12642,"avatar_url":"https://avatars0.githubusercontent.com/u/12642?v=4","gravatar_id":"","url":"https://api.github.com/users/kamipo","html_url":"https://github.com/kamipo","followers_url":"https://api.github.com/users/kamipo/followers","following_url":"https://api.github.com/users/kamipo/following{/other_user}","gists_url":"https://api.github.com/users/kamipo/gists{/gist_id}","starred_url":"https://api.github.com/users/kamipo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kamipo/subscriptions","organizations_url":"https://api.github.com/users/kamipo/orgs","repos_url":"https://api.github.com/users/kamipo/repos","events_url":"https://api.github.com/users/kamipo/events{/privacy}","received_events_url":"https://api.github.com/users/kamipo/received_events","type":"User","site_admin":false},"assignees":[{"login":"kamipo","id":12642,"avatar_url":"https://avatars0.githubusercontent.com/u/12642?v=4","gravatar_id":"","url":"https://api.github.com/users/kamipo","html_url":"https://github.com/kamipo","followers_url":"https://api.github.com/users/kamipo/followers","following_url":"https://api.github.com/users/kamipo/following{/other_user}","gists_url":"https://api.github.com/users/kamipo/gists{/gist_id}","starred_url":"https://api.github.com/users/kamipo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kamipo/subscriptions","organizations_url":"https://api.github.com/users/kamipo/orgs","repos_url":"https://api.github.com/users/kamipo/repos","events_url":"https://api.github.com/users/kamipo/events{/privacy}","received_events_url":"https://api.github.com/users/kamipo/received_events","type":"User","site_admin":false}],"requested_reviewers":[],"requested_teams":[],"milestone":null,"commits_url":"https://api.github.com/repos/rails/rails/pulls/31829/commits","review_comments_url":"https://api.github.com/repos/rails/rails/pulls/31829/comments","review_comment_url":"https://api.github.com/repos/rails/rails/pulls/comments{/number}","comments_url":"https://api.github.com/repos/rails/rails/issues/31829/comments","statuses_url":"https://api.github.com/repos/rails/rails/statuses/682f73e48e949d67cae338825bcdde4d60e260f0","head":{"label":"saveriomiroddi:saveriom/improve_error_message_for_invalid_association_model","ref":"saveriom/improve_error_message_for_invalid_association_model","sha":"682f73e48e949d67cae338825bcdde4d60e260f0","user":{"login":"saveriomiroddi","id":1595356,"avatar_url":"https://avatars2.githubusercontent.com/u/1595356?v=4","gravatar_id":"","url":"https://api.github.com/users/saveriomiroddi","html_url":"https://github.com/saveriomiroddi","followers_url":"https://api.github.com/users/saveriomiroddi/followers","following_url":"https://api.github.com/users/saveriomiroddi/following{/other_user}","gists_url":"https://api.github.com/users/saveriomiroddi/gists{/gist_id}","starred_url":"https://api.github.com/users/saveriomiroddi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/saveriomiroddi/subscriptions","organizations_url":"https://api.github.com/users/saveriomiroddi/orgs","repos_url":"https://api.github.com/users/saveriomiroddi/repos","events_url":"https://api.github.com/users/saveriomiroddi/events{/privacy}","received_events_url":"https://api.github.com/users/saveriomiroddi/received_events","type":"User","site_admin":false},"repo":{"id":118648325,"name":"rails-dev","full_name":"saveriomiroddi/rails-dev","owner":{"login":"saveriomiroddi","id":1595356,"avatar_url":"https://avatars2.githubusercontent.com/u/1595356?v=4","gravatar_id":"","url":"https://api.github.com/users/saveriomiroddi","html_url":"https://github.com/saveriomiroddi","followers_url":"https://api.github.com/users/saveriomiroddi/followers","following_url":"https://api.github.com/users/saveriomiroddi/following{/other_user}","gists_url":"https://api.github.com/users/saveriomiroddi/gists{/gist_id}","starred_url":"https://api.github.com/users/saveriomiroddi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/saveriomiroddi/subscriptions","organizations_url":"https://api.github.com/users/saveriomiroddi/orgs","repos_url":"https://api.github.com/users/saveriomiroddi/repos","events_url":"https://api.github.com/users/saveriomiroddi/events{/privacy}","received_events_url":"https://api.github.com/users/saveriomiroddi/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/saveriomiroddi/rails-dev","description":"My Rails development fork","fork":true,"url":"https://api.github.com/repos/saveriomiroddi/rails-dev","forks_url":"https://api.github.com/repos/saveriomiroddi/rails-dev/forks","keys_url":"https://api.github.com/repos/saveriomiroddi/rails-dev/keys{/key_id}","collaborators_url":"https://api.github.com/repos/saveriomiroddi/rails-dev/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/saveriomiroddi/rails-dev/teams","hooks_url":"https://api.github.com/repos/saveriomiroddi/rails-dev/hooks","issue_events_url":"https://api.github.com/repos/saveriomiroddi/rails-dev/issues/events{/number}","events_url":"https://api.github.com/repos/saveriomiroddi/rails-dev/events","assignees_url":"https://api.github.com/repos/saveriomiroddi/rails-dev/assignees{/user}","branches_url":"https://api.github.com/repos/saveriomiroddi/rails-dev/branches{/branch}","tags_url":"https://api.github.com/repos/saveriomiroddi/rails-dev/tags","blobs_url":"https://api.github.com/repos/saveriomiroddi/rails-dev/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/saveriomiroddi/rails-dev/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/saveriomiroddi/rails-dev/git/refs{/sha}","trees_url":"https://api.github.com/repos/saveriomiroddi/rails-dev/git/trees{/sha}","statuses_url":"https://api.github.com/repos/saveriomiroddi/rails-dev/statuses/{sha}","languages_url":"https://api.github.com/repos/saveriomiroddi/rails-dev/languages","stargazers_url":"https://api.github.com/repos/saveriomiroddi/rails-dev/stargazers","contributors_url":"https://api.github.com/repos/saveriomiroddi/rails-dev/contributors","subscribers_url":"https://api.github.com/repos/saveriomiroddi/rails-dev/subscribers","subscription_url":"https://api.github.com/repos/saveriomiroddi/rails-dev/subscription","commits_url":"https://api.github.com/repos/saveriomiroddi/rails-dev/commits{/sha}","git_commits_url":"https://api.github.com/repos/saveriomiroddi/rails-dev/git/commits{/sha}","comments_url":"https://api.github.com/repos/saveriomiroddi/rails-dev/comments{/number}","issue_comment_url":"https://api.github.com/repos/saveriomiroddi/rails-dev/issues/comments{/number}","contents_url":"https://api.github.com/repos/saveriomiroddi/rails-dev/contents/{+path}","compare_url":"https://api.github.com/repos/saveriomiroddi/rails-dev/compare/{base}...{head}","merges_url":"https://api.github.com/repos/saveriomiroddi/rails-dev/merges","archive_url":"https://api.github.com/repos/saveriomiroddi/rails-dev/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/saveriomiroddi/rails-dev/downloads","issues_url":"https://api.github.com/repos/saveriomiroddi/rails-dev/issues{/number}","pulls_url":"https://api.github.com/repos/saveriomiroddi/rails-dev/pulls{/number}","milestones_url":"https://api.github.com/repos/saveriomiroddi/rails-dev/milestones{/number}","notifications_url":"https://api.github.com/repos/saveriomiroddi/rails-dev/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/saveriomiroddi/rails-dev/labels{/name}","releases_url":"https://api.github.com/repos/saveriomiroddi/rails-dev/releases{/id}","deployments_url":"https://api.github.com/repos/saveriomiroddi/rails-dev/deployments","created_at":"2018-01-23T18:00:31Z","updated_at":"2018-01-23T18:02:39Z","pushed_at":"2018-01-31T23:24:09Z","git_url":"git://github.com/saveriomiroddi/rails-dev.git","ssh_url":"git@github.com:saveriomiroddi/rails-dev.git","clone_url":"https://github.com/saveriomiroddi/rails-dev.git","svn_url":"https://github.com/saveriomiroddi/rails-dev","homepage":"http://rubyonrails.org","size":158932,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":false,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":null,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"rails:master","ref":"master","sha":"889eb91d5f439eab647fbbef47886c61dc98e4e8","user":{"login":"rails","id":4223,"avatar_url":"https://avatars1.githubusercontent.com/u/4223?v=4","gravatar_id":"","url":"https://api.github.com/users/rails","html_url":"https://github.com/rails","followers_url":"https://api.github.com/users/rails/followers","following_url":"https://api.github.com/users/rails/following{/other_user}","gists_url":"https://api.github.com/users/rails/gists{/gist_id}","starred_url":"https://api.github.com/users/rails/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rails/subscriptions","organizations_url":"https://api.github.com/users/rails/orgs","repos_url":"https://api.github.com/users/rails/repos","events_url":"https://api.github.com/users/rails/events{/privacy}","received_events_url":"https://api.github.com/users/rails/received_events","type":"Organization","site_admin":false},"repo":{"id":8514,"name":"rails","full_name":"rails/rails","owner":{"login":"rails","id":4223,"avatar_url":"https://avatars1.githubusercontent.com/u/4223?v=4","gravatar_id":"","url":"https://api.github.com/users/rails","html_url":"https://github.com/rails","followers_url":"https://api.github.com/users/rails/followers","following_url":"https://api.github.com/users/rails/following{/other_user}","gists_url":"https://api.github.com/users/rails/gists{/gist_id}","starred_url":"https://api.github.com/users/rails/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rails/subscriptions","organizations_url":"https://api.github.com/users/rails/orgs","repos_url":"https://api.github.com/users/rails/repos","events_url":"https://api.github.com/users/rails/events{/privacy}","received_events_url":"https://api.github.com/users/rails/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/rails/rails","description":"Ruby on Rails","fork":false,"url":"https://api.github.com/repos/rails/rails","forks_url":"https://api.github.com/repos/rails/rails/forks","keys_url":"https://api.github.com/repos/rails/rails/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rails/rails/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rails/rails/teams","hooks_url":"https://api.github.com/repos/rails/rails/hooks","issue_events_url":"https://api.github.com/repos/rails/rails/issues/events{/number}","events_url":"https://api.github.com/repos/rails/rails/events","assignees_url":"https://api.github.com/repos/rails/rails/assignees{/user}","branches_url":"https://api.github.com/repos/rails/rails/branches{/branch}","tags_url":"https://api.github.com/repos/rails/rails/tags","blobs_url":"https://api.github.com/repos/rails/rails/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rails/rails/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rails/rails/git/refs{/sha}","trees_url":"https://api.github.com/repos/rails/rails/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rails/rails/statuses/{sha}","languages_url":"https://api.github.com/repos/rails/rails/languages","stargazers_url":"https://api.github.com/repos/rails/rails/stargazers","contributors_url":"https://api.github.com/repos/rails/rails/contributors","subscribers_url":"https://api.github.com/repos/rails/rails/subscribers","subscription_url":"https://api.github.com/repos/rails/rails/subscription","commits_url":"https://api.github.com/repos/rails/rails/commits{/sha}","git_commits_url":"https://api.github.com/repos/rails/rails/git/commits{/sha}","comments_url":"https://api.github.com/repos/rails/rails/comments{/number}","issue_comment_url":"https://api.github.com/repos/rails/rails/issues/comments{/number}","contents_url":"https://api.github.com/repos/rails/rails/contents/{+path}","compare_url":"https://api.github.com/repos/rails/rails/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rails/rails/merges","archive_url":"https://api.github.com/repos/rails/rails/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rails/rails/downloads","issues_url":"https://api.github.com/repos/rails/rails/issues{/number}","pulls_url":"https://api.github.com/repos/rails/rails/pulls{/number}","milestones_url":"https://api.github.com/repos/rails/rails/milestones{/number}","notifications_url":"https://api.github.com/repos/rails/rails/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rails/rails/labels{/name}","releases_url":"https://api.github.com/repos/rails/rails/releases{/id}","deployments_url":"https://api.github.com/repos/rails/rails/deployments","created_at":"2008-04-11T02:19:47Z","updated_at":"2018-01-31T23:55:22Z","pushed_at":"2018-01-31T23:24:13Z","git_url":"git://github.com/rails/rails.git","ssh_url":"git@github.com:rails/rails.git","clone_url":"https://github.com/rails/rails.git","svn_url":"https://github.com/rails/rails","homepage":"http://rubyonrails.org","size":159943,"stargazers_count":38478,"watchers_count":38478,"language":"Ruby","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":15585,"mirror_url":null,"archived":false,"open_issues_count":1061,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit"},"forks":15585,"open_issues":1061,"watchers":38478,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/rails/rails/pulls/31829"},"html":{"href":"https://github.com/rails/rails/pull/31829"},"issue":{"href":"https://api.github.com/repos/rails/rails/issues/31829"},"comments":{"href":"https://api.github.com/repos/rails/rails/issues/31829/comments"},"review_comments":{"href":"https://api.github.com/repos/rails/rails/pulls/31829/comments"},"review_comment":{"href":"https://api.github.com/repos/rails/rails/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/rails/rails/pulls/31829/commits"},"statuses":{"href":"https://api.github.com/repos/rails/rails/statuses/682f73e48e949d67cae338825bcdde4d60e260f0"}},"author_association":"NONE"}}
{"actor":{"display_login":"composerinteralia"}}