ember-data-updating-json-api-relationships
This addon adds support to Ember Data to update relationships independently. See Updating Relationships in the JSON:API spec for more details. This library works for updating to-one and to-many relationships, as described in the JSON:API spec.
Installation
ember install ember-data-updating-json-api-relationships
Getting Started
First, extend the adapter:
// app/adapters/application.js;; ;
Second, extend the serializer:
// app/serializers/application.js;; ;
Third, add the model mixin to the model with the relationship that you want to update independently:
// app/models/article.js;; let Model attr hasMany belongsTo = DS; ;
Lastly, call updateRelationship(relationship)
on your model:
article;article; // PATCH /articles/:id/relationships/tagsarticle; article; // PATCH /articles/:id/relationships/authorarticle;
Customizations
Customizing Relationship URLs
This addon will set relationship URLs to what is recommended in the spec, so something like /articles/:id/relationships/tags
for a to-many relationship and /articles/:id/relationships/author
for a to-one relationship. If you need to override this, use the urlForUpdateRelationship()
hook:
// app/adapters/article.js