How to change serialized Data based on the includeID flag in options?


#1

I am trying to massage the underlying data based on the options set in adapter.

Here is my adapter :slight_smile

import ApplicationAdapter from './application';

export default ApplicationAdapter.extend({
  pathForType: () => 'authors',
  updateRecord : function(store, type, snapshot) {
    var serializedData = snapshot.serialize({includeId: true});
    debugger;
    return this._super(...arguments);
  }
}); 

I have written a mixin that I use in the serializer :100:

    import Ember from 'ember';
    export default Ember.Mixin.create({
      serialize(snapshot, options) {
        let json = this._super(...arguments);

        debugger;
        if(!options.includeId) {  <- I get an error here.
          if('id' in json){
            delete json.id;
          }
        }
        return json;

      }
    });

All I am trying to do is that if IsInclude is true or false do something in the serializer and return the changed json. Also, how can I check the model passed to the serializer. Is there something like snapshot.record.type == “Authors”?


#2

Try snapshot.record.constructor.modelName.