问题
I have two models - sessions and tests (ember-data)
a Session has_many tests.
The thing is that in the JSON returned from the server (cannot be changed) has no test_ids in session object so I can't have it in the model.
I want to have the ability when I go to #/session/4 - to have ember have another server API call to <server_address>/rest/sessions/4/tests
and have it in a "tests" property
The current code:
App.Session = DS.Model.extend({
logicalId: DS.attr('string'),
.....
// tests: DS.hasMany('test', {async: true}) - wish I could do this
});
App.SessionSerializer = DS.ActiveModelSerializer.extend({
normalizePayload: function(payload) {
payload.sessions = payload.result;
delete payload.error;
delete payload.result;
delete payload.metadata;
return payload;
}
});
回答1:
You can try overriding buildURL
to create the correct URL you need for your specific case, this answer should help you
来源:https://stackoverflow.com/questions/26584475/emberdata-access-the-server-for-additional-data