Open newtonianb opened 9 years ago
Your data sample does not come close to representing what the JSON-API spec defines.
You'll most likely want to create a parse
function on your Comment
model that would transform user: { username: 'Bob' }
into { user: { id: 2 } }
then where you create the relation between User
and Comment
set parse: true
OR you could set the idAttribute
on your User
model to be username
which may cause issues elsewhere when fetching/saving.
We've been using Backbone Relational to model our ORM relationship in the front end for instance:
That has been working great using models such as this in the front end:
However now our api has changed and respecting more of the JSON-API Spec so the data from the back end is encapsulated inside of 'data'.
How can we instruct backbone relational to get the data for the 'comments' relation from .data instead of mapping the json structure directly?
For the ''class User'' we can implement the parse method like so
But how do we do this for the comments relation??