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

JSONAPI: Relationship IDs ignore as: :id option #193

Closed
dajinchu opened this issue Jul 14, 2016 · 2 comments
Closed

JSONAPI: Relationship IDs ignore as: :id option #193

dajinchu opened this issue Jul 14, 2016 · 2 comments

Comments

@dajinchu
Copy link

I'm using the as: option with :id inside a has_many relationship:

Representer

class ParentRepresenter < Roar::Decorator
  include Roar::JSON::JSONAPI
  type :parents

  has_many :children do
  type :children

  property :alias_id, as: :id
  link :self do
    parent_child_url(represented.parent.id, represented.alias_id)
  end
end

Output of respond_with

{
  "data": {
    "relationships": {
      "documents": {
        "data": [
          {
            "type": "documents",
            "id": ""
          }
        ],
        "links": {
          "self": "http://127.0.0.1:3000/parent/57879b4a3bb752aaa6e24a35/child/0"
        }
      }
    }
  },
  "included": [
    {
      "type": "documents",
      "id": "0",
      "attributes": {},
      "links": {
        "self": "http://127.0.0.1:3000/parent/57879b4a3bb752aaa6e24a35/child/0"
      }
    }
  ]
}

The ID is properly 0 in the included array, but empty in relationships.

Note:
I'm using roar-rails with the master branch of roar.
I'm also doing something a bit weird with the child IDs in my API. For each parent, they count up from 0, and so are not unique amongst all children, but are accessed through both the child and parent ID, ie. parent/:parent_id/children/child_id. That is why the child ID needs to be aliased, as they are stored in the database using unique ids, but only this separate index will be exposed through API.

@ghost
Copy link

ghost commented Sep 5, 2016

I confirm the same behavior with essentially the same setup

@myabc
Copy link
Contributor

myabc commented Dec 10, 2016

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

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