{"action":"opened","issue":{"url":"https://api.github.com/repos/jsonapi-rb/jsonapi-rails/issues/95","repository_url":"https://api.github.com/repos/jsonapi-rb/jsonapi-rails","labels_url":"https://api.github.com/repos/jsonapi-rb/jsonapi-rails/issues/95/labels{/name}","comments_url":"https://api.github.com/repos/jsonapi-rb/jsonapi-rails/issues/95/comments","events_url":"https://api.github.com/repos/jsonapi-rb/jsonapi-rails/issues/95/events","html_url":"https://github.com/jsonapi-rb/jsonapi-rails/issues/95","id":358273150,"node_id":"MDU6SXNzdWUzNTgyNzMxNTA=","number":95,"title":"Custom class name for relation that's not using Rails convention","user":{"login":"vtno","id":2187352,"node_id":"MDQ6VXNlcjIxODczNTI=","avatar_url":"https://avatars3.githubusercontent.com/u/2187352?v=4","gravatar_id":"","url":"https://api.github.com/users/vtno","html_url":"https://github.com/vtno","followers_url":"https://api.github.com/users/vtno/followers","following_url":"https://api.github.com/users/vtno/following{/other_user}","gists_url":"https://api.github.com/users/vtno/gists{/gist_id}","starred_url":"https://api.github.com/users/vtno/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vtno/subscriptions","organizations_url":"https://api.github.com/users/vtno/orgs","repos_url":"https://api.github.com/users/vtno/repos","events_url":"https://api.github.com/users/vtno/events{/privacy}","received_events_url":"https://api.github.com/users/vtno/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-09-08T07:31:22Z","updated_at":"2018-09-08T07:31:22Z","closed_at":null,"author_association":"NONE","body":"I have this `Course` model which has `has_many: quality_badges` relation but the actual class is named `CharacterQualityBadge` \r\n\r\n```\r\nclass Course < ApplicationRecord\r\n  ...\r\n  has_many :course_quality_badges\r\n  has_many :quality_badges, class_name: 'CharacterQualityBadge',\r\n                            foreign_key: :character_quality_badge_id,\r\n                            through: :course_quality_badges,\r\n                            dependent: :destroy\r\n  ...\r\nend\r\n```\r\n\r\nIn the controller I cannot do \r\n```\r\n# courses_controller.rb\r\nrender jsonapi: @course,\r\n               include: [\r\n                :course_locales, :course_schedules, :competency,\r\n                :quality_badges, :competency_badges\r\n               ]\r\n\r\n# serializable_course.rb\r\nattributes :name, ....\r\n...\r\nhas_many :quality_badges\r\n```\r\n\r\nIt'll throw `undefined method `new' for nil:NilClass` because there is no `QualityBadge` model class.\r\n\r\nI need to add an alias method in the Model and use it in the serializable class in order to make it work.  ( so: quality_badge -> character_quality_badge)\r\n\r\n```\r\n# course.rb\r\nclass Course < ApplicationRecord\r\n  ...\r\n  has_many :course_quality_badges\r\n  has_many :quality_badges, class_name: 'CharacterQualityBadge',\r\n                            foreign_key: :character_quality_badge_id,\r\n                            through: :course_quality_badges,\r\n                            dependent: :destroy\r\n\r\n  # This does not look so good to me.\r\n  def character_quality_badges\r\n    quality_badges \r\n  end\r\n  ...\r\nend\r\n\r\n# course_controller.rb\r\nrender jsonapi: @course,\r\n               include: [\r\n                :course_locales, :course_schedules, :competency,\r\n                :character_quality_badges, :competency_badges\r\n               ]\r\n\r\n# serializable_course.rb\r\nattributes :name, ....\r\n...\r\nhas_many :character_quality_badges\r\n```\r\n\r\nIt'd be great if I can specify the mapping of the class name inside `linkage` method or any other proper place like what you guys did for mapping resource with it serializer class.\r\n\r\n`render jsonapi: post, class: { Post: SerializableCustomPost }`\r\n\r\n"}}
{"actor":{"display_login":"vtno"}}