samedi 11 février 2017

Managing primaryKey in serializer

I have an application that uses the Slack API. Accordingly, I'm using a custom adapter and serializer.

I'm using these twice within the application; a query to retrieve multiple records and a queryRecord to retrieve a single record.

The response from the queryRecord does not contain the expected id primary key but works fine if I add primaryKey: 'ts'.

My question is this: what is the best way to manage this single difference between my query and queryRecord?

Do I need a different adapter and serializer for each? or is there a way to set primaryKey conditionally on the one serializer?

Adapter

export default Adapter.extend({
  defaultSerializer: 'slack',

  slack: Ember.inject.service(),

  query(store, type, params) {
    let slack = this.get('slack');
    let url = slack.buildURL(type.modelName, params.suffix);

    return slack.ajax(url, 'GET', params.data);
  },

  queryRecord(store, type, params) {
    let slack = this.get('slack');
    let url = slack.buildURL(type.modelName, params.suffix);

    return slack.ajax(url, 'GET', params.data);
  }
});

Serializer

//primaryKey: 'ts',

export default RESTSerializer.extend({
  isNewSerializerAPI: true,

  ...

});




Aucun commentaire:

Enregistrer un commentaire