I need to extend serializers/application.js in others serializers?


#1

Let’s say I have this serializers/application.js:

import Ember from 'ember';
import DS from 'ember-data';

export default DS.JSONAPISerializer.extend({

  keyForAttribute: function (attr) {
    return Ember.String.underscore(attr);
  },

});

Now I need another serializer for one of my model: serializers/post.js:

import DS from 'ember-data';

export default DS.JSONAPISerializer.extend({

  attrs: {
    my_game: {
      serialize: false
    }
  }

});

My serializer/post now doesn’t take automagically the code from serializers/application.js, so this code doesn’t work anymore in my post model:

keyForAttribute: function (attr) {
  return Ember.String.underscore(attr);
}

I need to extend the serializers/application.js in my serializers/post.js?


#2

Yes, that’s right. You need to extend it


#3

Can you show me how please?


#4

serializers/post

import AppSerializer from '{your-ember-app}/serializers/appliecation';

export default AppSerializer.extend({

});

#5

And if I already have this:

import DS from 'ember-data';
export default DS.JSONAPISerializer.extend({

........

});

???


#6

To extend your application serializer on your post serializer you will need to replace the 1st two lines with the ones I mentioned previously.