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
Post a Comment