{"action":"created","issue":{"url":"https://api.github.com/repos/rails-api/active_model_serializers/issues/1025","labels_url":"https://api.github.com/repos/rails-api/active_model_serializers/issues/1025/labels{/name}","comments_url":"https://api.github.com/repos/rails-api/active_model_serializers/issues/1025/comments","events_url":"https://api.github.com/repos/rails-api/active_model_serializers/issues/1025/events","html_url":"https://github.com/rails-api/active_model_serializers/issues/1025","id":98031653,"number":1025,"title":"Serializing Relationship Without Include","user":{"login":"jfelchner","id":285582,"avatar_url":"https://avatars.githubusercontent.com/u/285582?v=3","gravatar_id":"","url":"https://api.github.com/users/jfelchner","html_url":"https://github.com/jfelchner","followers_url":"https://api.github.com/users/jfelchner/followers","following_url":"https://api.github.com/users/jfelchner/following{/other_user}","gists_url":"https://api.github.com/users/jfelchner/gists{/gist_id}","starred_url":"https://api.github.com/users/jfelchner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jfelchner/subscriptions","organizations_url":"https://api.github.com/users/jfelchner/orgs","repos_url":"https://api.github.com/users/jfelchner/repos","events_url":"https://api.github.com/users/jfelchner/events{/privacy}","received_events_url":"https://api.github.com/users/jfelchner/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/rails-api/active_model_serializers/labels/0.10.x","name":"0.10.x","color":"bfd4f2"},{"url":"https://api.github.com/repos/rails-api/active_model_serializers/labels/JSON%20API","name":"JSON API","color":"CCCCCC"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-07-29T21:20:44Z","updated_at":"2015-10-02T15:12:09Z","closed_at":null,"body":"I've been looking through the code and there doesn't appear to be a way to serialize a `relationship` without also serializing an `include`.  Let me explain:\r\n\r\nWe have two systems.  In one we have, let's say, a `Product` and in the other we have, for example, an `Alert`.  An `Alert` has a `product_id` on it.  For the purposes of our backend systems, the alert system could care less about the `Product`.  All it needs is the ID.\r\n\r\nSo when I serialize the `Alert`, I want it to be able to generate the `relationship` but ignore the part where it puts the `include` section in.  I also don't want it to care about the model having a _literal_ association on it.  The `Alert` doesn't `belong_to :product` from an `ActiveRecord` perspective, but when the `Alert` JSON gets down to the client, the client will know how to go and fetch the product if it doesn't already have it.\r\n\r\nThis is what I was hoping that I could do:\r\n\r\n```ruby\r\nclass AlertSerializer < ActiveModel::Serializer\r\n  belongs_to :product, include: false,\r\n                       type:    'my_other_app_module_product'\r\nend\r\n```\r\n\r\nObviously, the default could be that if you say `belongs_to :product`, it would assume an attribute of `product_id` and a type of `product`, but overriding the `type` is important because sometimes (as in our case) it will not be able to be inferred from the association name.\r\n\r\nAnyway, the above would generate something like:\r\n\r\n```json\r\n{\r\n  \"data\" : {\r\n    \"type\" : \"my_app_module_alert\",\r\n    \"id\" : \"my_alert_id\",\r\n    \"attributes\" : {\r\n      /* Attributes */\r\n    },\r\n    \"relationships\" : {\r\n      \"product\" : {\r\n        \"data\" : { \"id\" : \"my_product_id\", \"type\" : \"my_other_app_module_product\" }\r\n      }\r\n    }\r\n  }\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/rails-api/active_model_serializers/issues/comments/145056583","html_url":"https://github.com/rails-api/active_model_serializers/issues/1025#issuecomment-145056583","issue_url":"https://api.github.com/repos/rails-api/active_model_serializers/issues/1025","id":145056583,"user":{"login":"scttnlsn","id":578446,"avatar_url":"https://avatars.githubusercontent.com/u/578446?v=3","gravatar_id":"","url":"https://api.github.com/users/scttnlsn","html_url":"https://github.com/scttnlsn","followers_url":"https://api.github.com/users/scttnlsn/followers","following_url":"https://api.github.com/users/scttnlsn/following{/other_user}","gists_url":"https://api.github.com/users/scttnlsn/gists{/gist_id}","starred_url":"https://api.github.com/users/scttnlsn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scttnlsn/subscriptions","organizations_url":"https://api.github.com/users/scttnlsn/orgs","repos_url":"https://api.github.com/users/scttnlsn/repos","events_url":"https://api.github.com/users/scttnlsn/events{/privacy}","received_events_url":"https://api.github.com/users/scttnlsn/received_events","type":"User","site_admin":false},"created_at":"2015-10-02T15:12:09Z","updated_at":"2015-10-02T15:12:09Z","body":"@NullVoxPopuli OK, I'm happy to put together a pull request if this is something you'd be interested in."}}