Skip to content

Question: Can relationship resources always have id and type? #94

Closed

Description

@andypike

Hello!

Firstly, I'm not 100% sure if this is the right place as I'm new to the gem. If it's not correct them I'm happy to move it as required.

We found this gem and am very excited about using it due to the very impressive performance. We are currently using ActiveModelSerializers in our app and are looking to migrate away in favour of this gem. I have everything working with the exception of one thing:

We have an Ember front-end and the devs on that team have said that when Ember uses a jsonapi API, we should always have id and type in the data object of a relationship as Ember maintains a data cache and if they are missing Ember will assume that those entities are no longer present. This should be irrespective of if the relationship is included or not.

For example, if we have a resource that belongs_to an account and we don't include account we get this:

"relationships": {
  "account":{
    "meta":{"included": false}
  }
}

If we include account we get this:

"relationships": {
  "account":{
    "data":{"type":"accounts","id":"26524"}
  }
}

Is it possible to always have the type and id of a related resource even if it isn't included? Maybe something like this is useful:

"relationships": {
  "account":{
    "data":{"type":"accounts","id":"26524"},
    "meta":{"included": false}
  }
}

This is the only thing stopping us from removing AMS and moving to jsonapi-rb.

Thanks in advance!

Andy

❤️

Activity

  1. changed the title [-]Question: Should relationship resources always have `id` and `type`?[/-] [+]Question: Can relationship resources always have `id` and `type`?[/+] on Dec 12, 2017
  2. beauby commented on Dec 12, 2017

    @beauby
    Member

    Hey, sure, simply do:

    belongs_to :account do
      linkage always: true
      # ...
    end
  3. andypike commented on Dec 12, 2017

    @andypike
    Author

    Thank you! Works a treat! 💜

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions