{"action":"created","comment":{"url":"https://api.github.com/repos/rails-api/active_model_serializers/pulls/comments/41082857","id":41082857,"diff_hunk":"@@ -42,13 +42,13 @@ class Serializer\n       def build_association(subject, parent_serializer_options)\n         association_value = subject.send(name)\n         reflection_options = options.dup\n-        serializer_class = ActiveModel::Serializer.serializer_for(association_value, reflection_options)\n+        serializer_class = subject.class.serializer_for(association_value, reflection_options)","path":"lib/active_model/serializer/reflection.rb","position":5,"original_position":5,"commit_id":"745cd829358be0d6b7851cf4fe0b622832efdb2a","original_commit_id":"745cd829358be0d6b7851cf4fe0b622832efdb2a","user":{"login":"beauby","id":2215778,"avatar_url":"https://avatars.githubusercontent.com/u/2215778?v=3","gravatar_id":"","url":"https://api.github.com/users/beauby","html_url":"https://github.com/beauby","followers_url":"https://api.github.com/users/beauby/followers","following_url":"https://api.github.com/users/beauby/following{/other_user}","gists_url":"https://api.github.com/users/beauby/gists{/gist_id}","starred_url":"https://api.github.com/users/beauby/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/beauby/subscriptions","organizations_url":"https://api.github.com/users/beauby/orgs","repos_url":"https://api.github.com/users/beauby/repos","events_url":"https://api.github.com/users/beauby/events{/privacy}","received_events_url":"https://api.github.com/users/beauby/received_events","type":"User","site_admin":false},"body":"`serializer_context_class`/`parent_serializer` (however we may call it) is not a reflection option but a serializer option. I agree that there is room for improvement though.","created_at":"2015-10-03T02:35:59Z","updated_at":"2015-10-03T02:35:59Z","html_url":"https://github.com/rails-api/active_model_serializers/pull/1225#discussion_r41082857","pull_request_url":"https://api.github.com/repos/rails-api/active_model_serializers/pulls/1225","_links":{"self":{"href":"https://api.github.com/repos/rails-api/active_model_serializers/pulls/comments/41082857"},"html":{"href":"https://github.com/rails-api/active_model_serializers/pull/1225#discussion_r41082857"},"pull_request":{"href":"https://api.github.com/repos/rails-api/active_model_serializers/pulls/1225"}}},"pull_request":{"url":"https://api.github.com/repos/rails-api/active_model_serializers/pulls/1225","id":46640580,"html_url":"https://github.com/rails-api/active_model_serializers/pull/1225","diff_url":"https://github.com/rails-api/active_model_serializers/pull/1225.diff","patch_url":"https://github.com/rails-api/active_model_serializers/pull/1225.patch","issue_url":"https://api.github.com/repos/rails-api/active_model_serializers/issues/1225","number":1225,"state":"open","locked":false,"title":"Add support for nested and namespaced serializers","user":{"login":"beauby","id":2215778,"avatar_url":"https://avatars.githubusercontent.com/u/2215778?v=3","gravatar_id":"","url":"https://api.github.com/users/beauby","html_url":"https://github.com/beauby","followers_url":"https://api.github.com/users/beauby/followers","following_url":"https://api.github.com/users/beauby/following{/other_user}","gists_url":"https://api.github.com/users/beauby/gists{/gist_id}","starred_url":"https://api.github.com/users/beauby/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/beauby/subscriptions","organizations_url":"https://api.github.com/users/beauby/orgs","repos_url":"https://api.github.com/users/beauby/repos","events_url":"https://api.github.com/users/beauby/events{/privacy}","received_events_url":"https://api.github.com/users/beauby/received_events","type":"User","site_admin":false},"body":"This is half of #1193. This PR brings lookup for serializer classes in different namespaces (namely that of the parent serializer, that of the resource, and finally in the global namespace), so that the following cases are not an issue anymore:\r\n\r\n```ruby\r\nmodule MyNamespace\r\n  class Post < AR\r\n    ...\r\n  end\r\n  class PostSerializer < AMS\r\n    has_many :comments\r\n  end\r\n\r\n  class CommentSerializer < AMS\r\n    ...\r\n  end\r\nend\r\n```\r\n(before, AMS would not find the `MyNamespace::CommentSerializer` as it would only look for `::CommentSerializer`)\r\n\r\nand\r\n\r\n```ruby\r\nclass PostSerializer < AMS\r\n  has_many :comments\r\n  class CommentSerializer < AMS\r\n    ...\r\n  end\r\nend\r\n```\r\n(this is a way to make single-purpose nested serializers contained in one class instead of polluting the global namespace and having to call them `PostCommentSerializer`).\r\n\r\nCases not handled yet:\r\n + looking up for a serializer in the root namespace of a chain of serializers (post has_many comments belongs_to author: when a `Post` is serialized with a `Namespace::PostSerializer`, we might want to look for `Namespace::AuthorSerializer`),\r\n + looking up for a serializer in the controller's namespace (when `Namespace::PostController` serializes a `Post`, we might want to look for `Namespace::PostSerializer`).","created_at":"2015-10-02T14:23:03Z","updated_at":"2015-10-03T02:35:59Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d84ed9e4cb51e4400daef593fd9c9e53984e32b9","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/rails-api/active_model_serializers/pulls/1225/commits","review_comments_url":"https://api.github.com/repos/rails-api/active_model_serializers/pulls/1225/comments","review_comment_url":"https://api.github.com/repos/rails-api/active_model_serializers/pulls/comments{/number}","comments_url":"https://api.github.com/repos/rails-api/active_model_serializers/issues/1225/comments","statuses_url":"https://api.github.com/repos/rails-api/active_model_serializers/statuses/745cd829358be0d6b7851cf4fe0b622832efdb2a","head":{"label":"beauby:nested-serializer-lookup","ref":"nested-serializer-lookup","sha":"745cd829358be0d6b7851cf4fe0b622832efdb2a","user":{"login":"beauby","id":2215778,"avatar_url":"https://avatars.githubusercontent.com/u/2215778?v=3","gravatar_id":"","url":"https://api.github.com/users/beauby","html_url":"https://github.com/beauby","followers_url":"https://api.github.com/users/beauby/followers","following_url":"https://api.github.com/users/beauby/following{/other_user}","gists_url":"https://api.github.com/users/beauby/gists{/gist_id}","starred_url":"https://api.github.com/users/beauby/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/beauby/subscriptions","organizations_url":"https://api.github.com/users/beauby/orgs","repos_url":"https://api.github.com/users/beauby/repos","events_url":"https://api.github.com/users/beauby/events{/privacy}","received_events_url":"https://api.github.com/users/beauby/received_events","type":"User","site_admin":false},"repo":{"id":30326986,"name":"active_model_serializers","full_name":"beauby/active_model_serializers","owner":{"login":"beauby","id":2215778,"avatar_url":"https://avatars.githubusercontent.com/u/2215778?v=3","gravatar_id":"","url":"https://api.github.com/users/beauby","html_url":"https://github.com/beauby","followers_url":"https://api.github.com/users/beauby/followers","following_url":"https://api.github.com/users/beauby/following{/other_user}","gists_url":"https://api.github.com/users/beauby/gists{/gist_id}","starred_url":"https://api.github.com/users/beauby/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/beauby/subscriptions","organizations_url":"https://api.github.com/users/beauby/orgs","repos_url":"https://api.github.com/users/beauby/repos","events_url":"https://api.github.com/users/beauby/events{/privacy}","received_events_url":"https://api.github.com/users/beauby/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/beauby/active_model_serializers","description":"ActiveModel::Serializer implementation and Rails hooks","fork":true,"url":"https://api.github.com/repos/beauby/active_model_serializers","forks_url":"https://api.github.com/repos/beauby/active_model_serializers/forks","keys_url":"https://api.github.com/repos/beauby/active_model_serializers/keys{/key_id}","collaborators_url":"https://api.github.com/repos/beauby/active_model_serializers/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/beauby/active_model_serializers/teams","hooks_url":"https://api.github.com/repos/beauby/active_model_serializers/hooks","issue_events_url":"https://api.github.com/repos/beauby/active_model_serializers/issues/events{/number}","events_url":"https://api.github.com/repos/beauby/active_model_serializers/events","assignees_url":"https://api.github.com/repos/beauby/active_model_serializers/assignees{/user}","branches_url":"https://api.github.com/repos/beauby/active_model_serializers/branches{/branch}","tags_url":"https://api.github.com/repos/beauby/active_model_serializers/tags","blobs_url":"https://api.github.com/repos/beauby/active_model_serializers/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/beauby/active_model_serializers/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/beauby/active_model_serializers/git/refs{/sha}","trees_url":"https://api.github.com/repos/beauby/active_model_serializers/git/trees{/sha}","statuses_url":"https://api.github.com/repos/beauby/active_model_serializers/statuses/{sha}","languages_url":"https://api.github.com/repos/beauby/active_model_serializers/languages","stargazers_url":"https://api.github.com/repos/beauby/active_model_serializers/stargazers","contributors_url":"https://api.github.com/repos/beauby/active_model_serializers/contributors","subscribers_url":"https://api.github.com/repos/beauby/active_model_serializers/subscribers","subscription_url":"https://api.github.com/repos/beauby/active_model_serializers/subscription","commits_url":"https://api.github.com/repos/beauby/active_model_serializers/commits{/sha}","git_commits_url":"https://api.github.com/repos/beauby/active_model_serializers/git/commits{/sha}","comments_url":"https://api.github.com/repos/beauby/active_model_serializers/comments{/number}","issue_comment_url":"https://api.github.com/repos/beauby/active_model_serializers/issues/comments{/number}","contents_url":"https://api.github.com/repos/beauby/active_model_serializers/contents/{+path}","compare_url":"https://api.github.com/repos/beauby/active_model_serializers/compare/{base}...{head}","merges_url":"https://api.github.com/repos/beauby/active_model_serializers/merges","archive_url":"https://api.github.com/repos/beauby/active_model_serializers/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/beauby/active_model_serializers/downloads","issues_url":"https://api.github.com/repos/beauby/active_model_serializers/issues{/number}","pulls_url":"https://api.github.com/repos/beauby/active_model_serializers/pulls{/number}","milestones_url":"https://api.github.com/repos/beauby/active_model_serializers/milestones{/number}","notifications_url":"https://api.github.com/repos/beauby/active_model_serializers/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/beauby/active_model_serializers/labels{/name}","releases_url":"https://api.github.com/repos/beauby/active_model_serializers/releases{/id}","created_at":"2015-02-04T23:25:42Z","updated_at":"2015-02-04T23:25:43Z","pushed_at":"2015-10-02T17:17:20Z","git_url":"git://github.com/beauby/active_model_serializers.git","ssh_url":"git@github.com:beauby/active_model_serializers.git","clone_url":"https://github.com/beauby/active_model_serializers.git","svn_url":"https://github.com/beauby/active_model_serializers","homepage":"","size":2277,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":false,"has_downloads":true,"has_wiki":false,"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":"rails-api:master","ref":"master","sha":"066990184b9c1f9a7342085c99e93723c2018b69","user":{"login":"rails-api","id":2820360,"avatar_url":"https://avatars.githubusercontent.com/u/2820360?v=3","gravatar_id":"","url":"https://api.github.com/users/rails-api","html_url":"https://github.com/rails-api","followers_url":"https://api.github.com/users/rails-api/followers","following_url":"https://api.github.com/users/rails-api/following{/other_user}","gists_url":"https://api.github.com/users/rails-api/gists{/gist_id}","starred_url":"https://api.github.com/users/rails-api/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rails-api/subscriptions","organizations_url":"https://api.github.com/users/rails-api/orgs","repos_url":"https://api.github.com/users/rails-api/repos","events_url":"https://api.github.com/users/rails-api/events{/privacy}","received_events_url":"https://api.github.com/users/rails-api/received_events","type":"Organization","site_admin":false},"repo":{"id":2889230,"name":"active_model_serializers","full_name":"rails-api/active_model_serializers","owner":{"login":"rails-api","id":2820360,"avatar_url":"https://avatars.githubusercontent.com/u/2820360?v=3","gravatar_id":"","url":"https://api.github.com/users/rails-api","html_url":"https://github.com/rails-api","followers_url":"https://api.github.com/users/rails-api/followers","following_url":"https://api.github.com/users/rails-api/following{/other_user}","gists_url":"https://api.github.com/users/rails-api/gists{/gist_id}","starred_url":"https://api.github.com/users/rails-api/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rails-api/subscriptions","organizations_url":"https://api.github.com/users/rails-api/orgs","repos_url":"https://api.github.com/users/rails-api/repos","events_url":"https://api.github.com/users/rails-api/events{/privacy}","received_events_url":"https://api.github.com/users/rails-api/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/rails-api/active_model_serializers","description":"ActiveModel::Serializer implementation and Rails hooks","fork":false,"url":"https://api.github.com/repos/rails-api/active_model_serializers","forks_url":"https://api.github.com/repos/rails-api/active_model_serializers/forks","keys_url":"https://api.github.com/repos/rails-api/active_model_serializers/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rails-api/active_model_serializers/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rails-api/active_model_serializers/teams","hooks_url":"https://api.github.com/repos/rails-api/active_model_serializers/hooks","issue_events_url":"https://api.github.com/repos/rails-api/active_model_serializers/issues/events{/number}","events_url":"https://api.github.com/repos/rails-api/active_model_serializers/events","assignees_url":"https://api.github.com/repos/rails-api/active_model_serializers/assignees{/user}","branches_url":"https://api.github.com/repos/rails-api/active_model_serializers/branches{/branch}","tags_url":"https://api.github.com/repos/rails-api/active_model_serializers/tags","blobs_url":"https://api.github.com/repos/rails-api/active_model_serializers/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rails-api/active_model_serializers/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rails-api/active_model_serializers/git/refs{/sha}","trees_url":"https://api.github.com/repos/rails-api/active_model_serializers/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rails-api/active_model_serializers/statuses/{sha}","languages_url":"https://api.github.com/repos/rails-api/active_model_serializers/languages","stargazers_url":"https://api.github.com/repos/rails-api/active_model_serializers/stargazers","contributors_url":"https://api.github.com/repos/rails-api/active_model_serializers/contributors","subscribers_url":"https://api.github.com/repos/rails-api/active_model_serializers/subscribers","subscription_url":"https://api.github.com/repos/rails-api/active_model_serializers/subscription","commits_url":"https://api.github.com/repos/rails-api/active_model_serializers/commits{/sha}","git_commits_url":"https://api.github.com/repos/rails-api/active_model_serializers/git/commits{/sha}","comments_url":"https://api.github.com/repos/rails-api/active_model_serializers/comments{/number}","issue_comment_url":"https://api.github.com/repos/rails-api/active_model_serializers/issues/comments{/number}","contents_url":"https://api.github.com/repos/rails-api/active_model_serializers/contents/{+path}","compare_url":"https://api.github.com/repos/rails-api/active_model_serializers/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rails-api/active_model_serializers/merges","archive_url":"https://api.github.com/repos/rails-api/active_model_serializers/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rails-api/active_model_serializers/downloads","issues_url":"https://api.github.com/repos/rails-api/active_model_serializers/issues{/number}","pulls_url":"https://api.github.com/repos/rails-api/active_model_serializers/pulls{/number}","milestones_url":"https://api.github.com/repos/rails-api/active_model_serializers/milestones{/number}","notifications_url":"https://api.github.com/repos/rails-api/active_model_serializers/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rails-api/active_model_serializers/labels{/name}","releases_url":"https://api.github.com/repos/rails-api/active_model_serializers/releases{/id}","created_at":"2011-12-01T06:39:26Z","updated_at":"2015-10-02T15:18:10Z","pushed_at":"2015-10-02T17:17:20Z","git_url":"git://github.com/rails-api/active_model_serializers.git","ssh_url":"git@github.com:rails-api/active_model_serializers.git","clone_url":"https://github.com/rails-api/active_model_serializers.git","svn_url":"https://github.com/rails-api/active_model_serializers","homepage":"","size":7322,"stargazers_count":3011,"watchers_count":3011,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":689,"mirror_url":null,"open_issues_count":154,"forks":689,"open_issues":154,"watchers":3011,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/rails-api/active_model_serializers/pulls/1225"},"html":{"href":"https://github.com/rails-api/active_model_serializers/pull/1225"},"issue":{"href":"https://api.github.com/repos/rails-api/active_model_serializers/issues/1225"},"comments":{"href":"https://api.github.com/repos/rails-api/active_model_serializers/issues/1225/comments"},"review_comments":{"href":"https://api.github.com/repos/rails-api/active_model_serializers/pulls/1225/comments"},"review_comment":{"href":"https://api.github.com/repos/rails-api/active_model_serializers/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/rails-api/active_model_serializers/pulls/1225/commits"},"statuses":{"href":"https://api.github.com/repos/rails-api/active_model_serializers/statuses/745cd829358be0d6b7851cf4fe0b622832efdb2a"}}}}