import DS from 'ember-data';
export default DS.Model.extend({
nb: DS.attr('number')
});
And, in my template, i use:
{{input name="mynb" value=(mut model.nb)}}
But when i use nb in my controller after changed its value with this input, nb become a string?! I thought ember-data cast it to a number before store it (and not only when i send my modified model to my backend server). No?
Will we have to create an action in the controller or a Computed Property in the model to perform this type casting ?
Also, that type you give to DS.attr only get looked at by serializer. It does the conversion when it get send to the server, but not before. If you have a custom serializer, it’s possible this step is skipped altogether.
Because input will casting this value to strings, it always does even if you specify type=number, no need to worry it to much because ember data serializer will handle that for you, but if you need to do mathematic calculation in other layer, components for example, you need to cast it back to number explicitly.
I’s actually what I understood . Ember-data does not auto cast the attributes when store the data. So I created a component {{numeric-field}} to be sure to return a Number.