mercredi 15 mars 2017

how to serialize nested object without creating a serializer for the model in ember

I know that if I want to serialize nested comments of a model called post, I need to create a serializer in app/serializer/post.js something like :

import RESTSerializer from 'ember-data/serializers/rest';
import DS from 'ember-data';

export default RESTSerializer.extend(DS.EmbeddedRecordsMixin, {
  attrs: {
      comments: {embedded: 'always'}
  }
});

but what if I want to serialize this inside the app/serlizer/application.js ? I dont want to define a serializer for each model. Instead I want to be able to resolve the belong-to or has-many relationship inside the normalizeQueryResponse for example.

normalizeQueryResponse(store, primaryModelClass, payload, id, requestType) {
    console.log(payload);
    return this._normalizeResponse(store, primaryModelClass, payload, id, requestType, true);
  },

I want to be able to go thorough the payload and if a property in payload turned out to be object then resolve that.

does anyone know if that is possible?




Aucun commentaire:

Enregistrer un commentaire