Data: JSONAPI PATCH relationship not defaulting to nested resource URL

Created on 23 Aug 2016  路  5Comments  路  Source: emberjs/data

// User model.js
job: belongsTo('job')
// Job model.js
user: belongsTo('user')
// When saving relationship change 
job.set('user', [a user model or null if removing the association between the two]);
job.save();

When using the default JSONAPI adapter, this type of record update does not default to the nested resource URL (/job/:job_id/relationships/user) and instead just uses /job/:job_id/.

I'm not sure if this is a symptom/side-affect of https://github.com/emberjs/data/issues/3467

links

Most helpful comment

Unfortunately this is not possible at the moment, as links are not fully supported yet. This is somewhat tracked in #2905 under Miscellaneous > Improve link handling.

I think this will be supported using references once RFC#160 (or similar) is implemented: job.belongsTo('user').save().

This is related to #3733, which is about saving hasMany relationships.

All 5 comments

Unfortunately this is not possible at the moment, as links are not fully supported yet. This is somewhat tracked in #2905 under Miscellaneous > Improve link handling.

I think this will be supported using references once RFC#160 (or similar) is implemented: job.belongsTo('user').save().

This is related to #3733, which is about saving hasMany relationships.

  1. I don't have the same issue with creating records, is that due to the fact that Ember data doesn't do relationship dirty tracking right now?
  2. Once the links support is implemented, it would just mean we'd have to have something like
...
user: {
  links: {
    self: 'jobs/1234/relationships/user'
  }
}
...

in our payload, correct?

@pangratz it seems like a major oversight, unless I've misunderstood this issue? From what I understand, If you take the example of posting and deleting comments on an article, there is no way currently to do this using relationship links, meaning the full array of all comments is sent in a PATCH request - unscalable and unusable.

@BenKingBBC I agree. We're running into major scalability issues by sending the array every time.

Closing this as we're tracking self link support in #2905 (I also updated that one to be a bit clearer on self link support for relationships)

Was this page helpful?
0 / 5 - 0 ratings