Reputation: 1072
I have two APIs, let's say :
aaa.com/api/v1/events
bbb.com/api/events
Both implement JSONAPI adapter, and then return a payload with type="events"
.
As a result, I have to scope those models into subfolders:
models/aaa/event.js
models/bbb/event.js
Which result in querying the models this way:
this.get('store').findAll('aaa/event');
Then, I have implemented an adapter:
// adapters/aaa/event.js
import config from '../../config/environment';
import DS from 'ember-data';
import Ember from "ember";
const { String } = Ember;
export default DS.JSONAPIAdapter.extend({
host: 'aaa.com',
namespace: 'api/v1',
pathForType: function(type) {
return String
.underscore(type) // `aaa/some-model` -> `aaa/some_model`
.pluralize() // `aaa/some_model` -> `aaa/some_models`
.replace("aaa/", ""); // `aaa/some_model` -> `some_model`
},
});
So far so good, Ember correctly calls aaa.com/api/v1/events
, the returned payload is typed events
but Ember fails to translate it to aaa/events
.
How can I proceed ?
Upvotes: 2
Views: 243
Reputation: 12872
So you got the model specific serializer for aaa/event
and bbb/event
. you can overridre modelNameFromPayloadType
method to translate events
to your required model name aaa/events
.
For aaa/event serializer,
modelNameFromPayloadType(payloadType) {
return 'aaa/event';
}
Upvotes: 1