{"action":"created","issue":{"url":"https://api.github.com/repos/rails-api/active_model_serializers/issues/1342","labels_url":"https://api.github.com/repos/rails-api/active_model_serializers/issues/1342/labels{/name}","comments_url":"https://api.github.com/repos/rails-api/active_model_serializers/issues/1342/comments","events_url":"https://api.github.com/repos/rails-api/active_model_serializers/issues/1342/events","html_url":"https://github.com/rails-api/active_model_serializers/issues/1342","id":118543599,"number":1342,"title":"has_many uses the wrong serializer","user":{"login":"bufordtaylor","id":214319,"avatar_url":"https://avatars.githubusercontent.com/u/214319?v=3","gravatar_id":"","url":"https://api.github.com/users/bufordtaylor","html_url":"https://github.com/bufordtaylor","followers_url":"https://api.github.com/users/bufordtaylor/followers","following_url":"https://api.github.com/users/bufordtaylor/following{/other_user}","gists_url":"https://api.github.com/users/bufordtaylor/gists{/gist_id}","starred_url":"https://api.github.com/users/bufordtaylor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bufordtaylor/subscriptions","organizations_url":"https://api.github.com/users/bufordtaylor/orgs","repos_url":"https://api.github.com/users/bufordtaylor/repos","events_url":"https://api.github.com/users/bufordtaylor/events{/privacy}","received_events_url":"https://api.github.com/users/bufordtaylor/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":17,"created_at":"2015-11-24T06:45:43Z","updated_at":"2015-12-09T12:11:02Z","closed_at":null,"body":"Banging my head trying to figure out what is going on here. on 0.10.0.rc3\r\n\r\n```ruby\r\n   class Project < ActiveRecord::Base\r\n      has_many :roles\r\n   end\r\n\r\n   class Role < ActiveRecord::Base\r\n      has_many :auditions\r\n   end\r\n\r\n   class Audition < ActiveRecord::Base\r\n   end\r\n\r\n   class ProjectSerializer < ActiveModel::Serializer\r\n      attributes :id\r\n      has_many :roles\r\n   end\r\n\r\n   class RoleSerializer < ActiveModel::Serializer\r\n      attributes :id\r\n      has_many :auditions\r\n   end\r\n\r\n   class AuditionSerializer < ActiveModel::Serializer\r\n      attributes :id\r\n   end\r\n\r\n```\r\n\r\noutput using no config adapter\r\n\r\n```\r\n{\r\n  id: 6806,\r\n  roles: [\r\n    {\r\n      id: 49371\r\n    }\r\n}\r\n```\r\n\r\noutput using json adapter\r\n\r\n```\r\n{\r\n  project: {\r\n    id: 6806,\r\n    roles: [\r\n      {\r\n        id: 49371\r\n      }\r\n}\r\n```\r\n\r\noutput using json_api adapter\r\n\r\n```\r\ndata: {\r\n  id: \"6806\",\r\n  type: \"projects\",\r\n  relationships: {\r\n    roles: {\r\n      data: [\r\n        {\r\n           id: \"49371\",\r\n           type: \"roles\"\r\n        }\r\n   included: [\r\n     {\r\n        id: \"49371\",\r\n        type: \"roles\",\r\n        relationships: {\r\n           auditions: {\r\n             data: [\r\n               {\r\n                 id: \"57617\",\r\n                 type: \"auditions\"\r\n               }\r\netc...\r\n```\r\nFor sanity, Role.find(49371) has records of auditions in the database. Why do the audition records only appear on the json_api adapter?\r\n\r\nI tried a few things to try to get it to work on the non json_api adapters, like\r\n\r\n```has_many :auditions, serializer: AuditionSerializer```\r\n\r\nSame result.\r\n\r\nEven tried this\r\n\r\n```ruby\r\n   class RoleSerializer < ActiveModel::Serializer\r\n      attributes :id, :auditions\r\n      def auditions\r\n          object.auditions.each do |aud|\r\n              AuditionSerializer.new(aud)\r\n          end\r\n      end\r\n   end\r\n```\r\nThis *did* get auditions to show on non json_api adapters, but it *did not* use the AuditionSerializer, as it contained `created_at` and other attributes I did not set.\r\n\r\nThe crazy thing is that is **IS** calling AuditionSerializer, as I overrode the `initialize` method to check if it's being called, but it's still outputting the wrong attributes.\r\n\r\n\r\nMore crazy things:\r\n\r\n`ap ActiveModel::SerializableResource.new(Role.find(49371)).serializable_hash` yields results **with** auditions\r\n`ap ActiveModel::SerializableResource.new(Project.find(6806)).serializable_hash` yields results **without** auditions regardless of the adapter\r\n\r\nJust tried in 0.9.0. Worked fine."},"comment":{"url":"https://api.github.com/repos/rails-api/active_model_serializers/issues/comments/163205562","html_url":"https://github.com/rails-api/active_model_serializers/issues/1342#issuecomment-163205562","issue_url":"https://api.github.com/repos/rails-api/active_model_serializers/issues/1342","id":163205562,"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},"created_at":"2015-12-09T12:11:02Z","updated_at":"2015-12-09T12:11:02Z","body":"@bf4: Agreed that for the \"legacy\" Attributes/Json adapters, it can lead to possible infinite recursions and almost certain duplications. But those are actually design flaws in the structuring of data, not in the serialization process. However, I'm personally fine with it, I just wanted the reasons to be stated for the record."}}