1👍
The serializer are used to customize the loading and saving (or serialization and deserialization) of data.
To customize the URLs you must use an Adapter,(e.g. RESTAdapter is my most used adapter).
That will work in the case you want to create (urlForCreateRecord
) or update (urlForUpdateRecord
) tasks but it may not directly work if you just want to convert a work.get('tasks')
following a belongsTo
relationship to a GET http://endpoint/work/<work_id>/tasks
, at least in my case it didn’t “just work”ed.
A solution I found that works very well is adding a property links
as a plain object to the parent objects that contains links to the different child models you want to retrieve as properties.
Something like this:
/* app/adapters/work.js */
import DS from 'ember';
export default DS.RESTSerializer({
normalize (model, hash, prop) {
hash.links = hash.links || {};
hash.links.tasks = this.buildURL(model, hash.id) + '/tasks';
return this._super(model, hash, prop);
}
});
In this example, when Ember try to get a tasks property from a work model, it will make a GET to the URL that work.links.tasks
contains.