Reputation: 1749
My question is in line with this one: Ember data 1.0.0: confused with per-type adapters and serializers
Problem is that I cannot initialize RESTSerializer per type because I need to set ActiveModelSerializer :
App.FooSerializer = DS.ActiveModelSerializer.extend({attrs: {}});
to set relationships as embedded.
So I want to set 1 serializer for all models. I tried to set ApplicationSerializer
, but this did not call any hooks when getting response from server (And I'm sure my server gives correct response):
App.ApplicationSerializer = DS.RESTSerializer.extend({
extractSingle: function(store, type, payload, id, requestType) {
return this._super(store, type, payload, id, requestType);
},
extractArray: function(store, type, payload, id, requestType) {
return this._super(store, type, payload, id, requestType);
},
normalize: function(type, property, hash) {
return this._super(type, property, hash);
}
});
Setting my adapter doesn't seem to work:
var adapter = require('init/adapter');
App.ApplicationAdapter = adapter.extend({
defaultSerializer: myAdapter //I QUESS THIS IS WRONG?
});
Did I make a syntax error? Any other suggestions?
EDIT:
Ok, I found my mistake but not a great solution. Seems that my FooSerializer overrides the general ApplicationSerializer..
Is there a way where I can set both? :/
Upvotes: 1
Views: 83
Reputation: 47367
You can't use both per say, but you can have your FooSerializer
extend your ApplicationSerializer
and then override the methods that you'd like to use differently.
App.FooSerializer = App.ApplicationSerializer.extend({
extractArray: function(store, type, payload, id, requestType) {
// alert each record to annoy the user
return this._super(store, type, payload, id, requestType);
},
});
Upvotes: 2