0.0.10 • Published 6 years ago

ember-data-save-relationships v0.0.10

Weekly downloads
257
License
MIT
Repository
github
Last release
6 years ago

ember-data-save-relationships

NOTE: I have taken over maintenance from frank06/ember-data-save-relationships


Include this mixin in your serializers and it will save your hasMany and belongsTo relationships' records.

For example:

// app/serializers/artist.js

import JSONAPISerializer from 'ember-data/serializers/json-api';
import SaveRelationshipsMixin from 'ember-data-save-relationships';

export default JSONAPISerializer.extend(SaveRelationshipsMixin, {
  attrs: {
    albums: { serialize: true }
  }
});

Now an Artist payload may include attributes like:

data: {
  id: null,
  type: "artist",
  attributes: {
    name: "Radiohead"
  },
  relationships: {
    albums: {
      data: [
        {
          id: null,
          type: "albums",
          attributes: {
            name: "Kid A",
            __id__: "0internal-model"
          }
        }
      ]
    }
  }
}

More info: http://emberigniter.com/saving-models-relationships-json-api/

Installation

  • npm install --save-dev 'laborvoices/ember-data-save-relationships#master'

Notes

  • A temporary ID (__id__) will be sent along with the relationship's data attributes. Your server API must return this attribute intact along with a proper id after saving the relationship records:

     { 
       data: {
         id: "1",
         type: 'albums',
         attributes: { name: "Kid A"},
         relationships: {
           artists: {
             data: {
               id: "1",
               type: "artists",
               attributes: {
                 name: "Radiohead XXXX",
                 __id__: internalId
               }
             }
           }
         }
       }
     }

    Or it may alternatively be returned using the included array:

     { 
       data: {
         id: "1",
         type: 'albums',
         attributes: { name: "Kid A"},
         relationships: {
           artists: {
             data: {
               id: "1",
               type: "artists"
             }
           }
         }
       },
    
       included: [
         {
           id: "1",
           type: "artists",
           attributes: {
             name: "Radiohead XXXX",
             __id__: internalId
           }
         }
       ]
     }
  • Calling serialize: true on cyclic dependencies will result in a stack overflow

  • At this point in time, if your server returns updated attributes, these will not be updated in the Ember Data store

Issues

Please file at https://github.com/laborvoices/ember-data-save-relationships/issues

0.0.10

6 years ago

0.0.9

6 years ago

0.0.8

6 years ago

0.0.5

8 years ago

0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago

0.0.0

8 years ago