has many - Ember Data JSON-API hasMany: How? -


i'm familiar old ember-data "sideloading" model, this: ```

{   authors:[     {id:1, name:"ernest", type: 'author', books: [1,2]   ],   books: [     {id:1, name: "for whom bell tolls", type: 'book', author:1},     {id:2, name: "farewell arms", type: 'book', author:1}   ] } 

but new json-api method different.

for 1 thing, (and this), attributes separated id , type information, preventing namespace collisions.

i don't yet understand how hasmany relationship json-api format. can point me doc or article on how expected? examples on json-api page show individual relationships, not hasmany.

if write above example in new format, you'd have answered question.

i believe found answer in the json-api spec.

if correct in reading, each model have relationships key, value object key each named relationship, has data key can either single object or array hasmany relationship.

in case, above example be:

{   data: [     {id:1, type:'author', attributes: {name: "ernest"},       relationships:[         books:{           data: [             {type: 'book', id: 1},             {type: 'book', id: 2},           ]         }       ]     },     {id:1, type:'book', attributes: {name: "for whom bell tolls"},       relationships:{         author:{           data: {type: 'author', id: 1}         }       }     },     {id:2, type:'book', attributes: {name: "farewell arms"},       relationships:{         author:{           data: {type: 'author', id: 1}         }       }     },   ] } 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -