Mapping data external API

Hey guys. someone can help me about how consuming an API using Ember. I have a model called product

export default DS.Model.extend({
  url: DS.attr('string'),
  variations: [], //? 
})

But i can’t access nested data called ‘variations’ , its possible make this using emberjs. Below an example my API.

	data: {
	  url: "xxx-xxx-xxx",
	    variations: [
	      {
		factsheet: { },
		reference: "xxxx--xx-x-x",
		brand: "LG",
		url: "http://",
		sellers: [],
		ean: "1234567",
		composite_id: "123456789",
		attributes: [],
		description: "xxxx..xxx",
		title: "testing",
		media: {},
		id: "19",
		is_delivery_available: true,
	      }
	    ]
	}

Well you could create your model like this:

export default DS.Model.extend({
  url: DS.attr('string'),
  variations: DS.attr()
})

Which doesn’t use a transform, it just passes the data straight through. But there are a lot of reasons that you don’t want to do that (none of the Ember Data niceties tend to work with nested data like that). It would be FAR preferable to make another model called “variation” and add a hasMany(‘variation’) relationship or something along those lines.

1 Like