Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON API Serialize deep relationships #200

Closed
wuarmin opened this issue Sep 27, 2016 · 1 comment
Closed

JSON API Serialize deep relationships #200

wuarmin opened this issue Sep 27, 2016 · 1 comment

Comments

@wuarmin
Copy link

wuarmin commented Sep 27, 2016

I know JSON API module is not finished yet, but maybe this can be accomplished with less effort. In my opinion the serialized compound doc, generated from following code, should contain the ressource object (type: organisations, id: 8) in the included-payload.

require 'roar/json'
require 'roar/decorator'
require 'roar/json/json_api'

class ArticleDecorator < Roar::Decorator
  include Roar::JSON::JSONAPI
  type :articles

  property :id
  property :title


  has_one :author, class: Authors do
    type :authors

    property :id
    property :email

    has_one :organisation, class: Organisations do
      type :organisations

      property :id
      property :name
    end
  end

end

organisation = Organisations.new(id: 8, name: 'Articles23')
author = Authors.new(id: 4711, email: 'author@test.com', organisation: organisation)
article = Articles.new(id: 1, author: author, title: 'Programming')

puts ArticleDecorator.new(article).to_json

The result json contains the relationship, but the ressource-object is missing:

{
  "data": {
    "type": "articles",
    "id": "1",
    "attributes": {
      "title": "Programming"
    },
    "relationships": {
      "author": {
        "data": {
          "type": "authors",
          "id": "4711"
        }
      }
    }
  },
  "included": [
    {
      "type": "authors",
      "id": "4711",
      "attributes": {
        "email": "author@test.com"
      },
      "relationships": {
        "organisation": {
          "data": {
            "type": "organisations",
            "id": "8"
          }
        }
      }
    }
  ]
}

best regards

@myabc
Copy link
Contributor

myabc commented Dec 10, 2016

This issue was moved to trailblazer/roar-jsonapi#2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants