DEBUG: -------------------------------
DEBUG: Ember : 2.6.1
DEBUG: Ember Data : 2.6.1
DEBUG: jQuery : 2.1.4
DEBUG: Ember Simple Auth : 1.1.0-beta.3
DEBUG: -------------------------------

this only happens sometimes, but it seems like it's not trying to singularize the events type to event.
I have an event model, and if I refresh the page, I don't get no model was found for 'events'. So, not sure why this is happening only sometimes.
Here is the action that triggers the request:
refreshStripe() {
let id = this.get('model.id');
let url = ENV.host + '/api/orders/' + id + '/refresh_stripe';
let authToken = this.get('session.data.authenticated.token');
Ember.$.ajax({
url: url,
type: 'GET',
beforeSend(xhr) {
xhr.setRequestHeader('Authorization', 'Bearer ' + authToken);
}
}).then(data => {
this.get('store').push(data);
}, error => {
let json = JSON.parse(error.responseText);
let errors = json.errors;
this.get('flashMessages').alert(errors);
});
}
Here is a fiddle demonstrating the error: https://ember-twiddle.com/46a491da1f665904b4647f181a85aa2f
It looks like this has to do with only polymorphic relationships?
idk.
@Serabe said
Seems like emberjs/data only accepts singularize type in belongsTo relationships. As of JSONAPI Identification, this might be a bug.
Which isn't a problem, I just need to know i this is something I need to fix in ActiveModelSerializers, or if Ember-data _should_ support plural type values.
This seems to be something new to 2.6?
oh, it looks like the JSON API spec says it could be either (singular or plural), I understand what @Serabe was saying now.
This also happens on Ember Data 2.5.0, and 2.4.0
The JSON API format that the store.push method accepts is a little stricter then the base JSON API spec. Ember Data expects all of the type names, attributes and relationships to match the format of the types an relationships in your Ember Model definitions.
Normally when you do store.findRecord normally Ember Data runs the response through the serializer which is responsible for converting the response payload into the format that Ember Data expects. (The default JSONAPISerializer, singularizes the model names and camel cases the attribute and relationship names so they match 1 to 1 with the DS.attr/DS.belongsTo/DS.hasMany definitions on the model class.)
In your twiddle Ember Data is missing the serializer step that normally happens before store.push. Ember Data has a connivence method store.pushPayload which uses the serializer to extract the payload before pushing the model into the store. If you replace store.push with store.pushPayload I suspect it will fix your issue.
that was it, thanks!
Most helpful comment
The JSON API format that the
store.pushmethod accepts is a little stricter then the base JSON API spec. Ember Data expects all of the type names, attributes and relationships to match the format of the types an relationships in your Ember Model definitions.Normally when you do
store.findRecordnormally Ember Data runs the response through the serializer which is responsible for converting the response payload into the format that Ember Data expects. (The default JSONAPISerializer, singularizes the model names and camel cases the attribute and relationship names so they match 1 to 1 with theDS.attr/DS.belongsTo/DS.hasManydefinitions on the model class.)In your twiddle Ember Data is missing the serializer step that normally happens before
store.push. Ember Data has a connivence methodstore.pushPayloadwhich uses the serializer to extract the payload before pushing the model into the store. If you replacestore.pushwithstore.pushPayloadI suspect it will fix your issue.