attrs{Object}
The attrs object can be used to declare a simple mapping between property names on DS.Model records and payload keys in the serialized JSON object representing the record. An object with the property key can also be used to designate the attribute's key on the response payload.
Example
app/models/person.jsimport DS from 'ember-data';
export default DS.Model.extend({
firstName: DS.attr('string'),
lastName: DS.attr('string'),
occupation: DS.attr('string'),
admin: DS.attr('boolean')
});
app/serializers/person.jsimport DS from 'ember-data';
export default DS.JSONSerializer.extend({
attrs: {
admin: 'is_admin',
occupation: { key: 'career' }
}
});
You can also remove attributes by setting the serialize key to false in your mapping object.
Example
app/serializers/person.jsimport DS from 'ember-data';
export default DS.JSONSerializer.extend({
attrs: {
admin: { serialize: false },
occupation: { key: 'career' }
}
});
When serialized:
{
"firstName": "Harry",
"lastName": "Houdini",
"career": "magician"
}
Note that the admin is now not included in the payload.
Please login to continue.