My data comes from REST API like this:
customers:[
id:3,
name:"Joue",
currency:{
id:5
iso_code:"BDT"
}
]
My model:
App.Customer = DS.Model.extend({
name: DS.attr('string'),
currency: DS.attr('string')
});
i populated a select box with the availabe currencies and now i want to select by "id" 5. Since currency is embedded and its interpreted as string i cant access it. As far as i know embedded records are no longer supported in ember-data 1.0.
do i have to rewrite my REST Api and get rid of the relationships or there is a workaround .
currency
is not "embedded", it's just an object. Don't declare it as a string in your model:You say you want to "select" by
id
--what do you actually want to do? You can access the properties ofcurrency
directly:No need for additional complexity involving serializers or additional models. However, you need to be careful when changing currency id, since
will not dirty the model and it won't save. You'll need to also incant
You can just create a custom serializer for the data.
Using your data (slightly modified, since the json isn't valid, and I'm guessing that's just cause it was hand written?)
Here's a serializer for that particular response type (read more about it here https://github.com/emberjs/data/blob/master/TRANSITION.md)
And your models defined with a relationship
Example:
http://emberjs.jsbin.com/OxIDiVU/535/edit