0

I get JSON with structure like this:

{
  "description":"text",
  "images":[{"id":"1","url":"image url"},{"id":"2","url":"url"}],
  "seats":3,
  "taken_seats":[{"number":1,"id":"1"},{"number":3,"id":"2"}],
  "title":"vel ad eius",
  "id":"1",
  "options":[]
}

How to structurize DS.model to handle it?

xamenrax
  • 1,724
  • 3
  • 27
  • 47

1 Answers1

1

String values (description, title) will use a DS.attr('string')

Number (seats) will use a DS.attr('number')

Arrays (images, taken_seats, options) will use a relation like DS.hasMany('App.Image'), you will have to set the mapping in the adapter to embedded see here for details.

You may feel like you do not need a relationship for arrays, like for example if you do not want / can list the possible keys of object in the options array. The solution would be to register a custom transform for your needs then you may encounter some unexcepted behavior, particularly with the isDirty flag of the object, see here for details

Community
  • 1
  • 1
Adrien Coquio
  • 4,870
  • 2
  • 24
  • 37