I have the following models:
//app/models/primary.js
export default DS.Model.extend(Validations, {
number: DS.attr('string'),
protocolDate: DS.attr('date'),
document: DS.belongsTo('document'),
origin: DS.belongsTo('origin')
});
//app/models/document.js
export default DS.Model.extend(Validations, {
number: DS.attr('string')
});
//app/models/origin.js
export default DS.Model.extend(Validations, {
number: DS.attr('string')
});
And these serializers:
//app/serializers/application.js
import Ember from 'ember';
import DS from 'ember-data';
export default DS.RESTSerializer.extend({
normalizeSingleResponse(store, primaryModelClass, payload /*, id, requestType*/ ) {
return this._super(...arguments);
},
normalizeArrayResponse(store, primaryModelClass, payload /*, id, requestType*/ ) {
return this._super(...arguments);
},
keyForAttribute(key) {
return Ember.String.underscore(key);
},
keyForRelationship(key) {
return Ember.String.underscore(key);
}
});
//app/serializers/primary.js
import DS from 'ember-data';
import ApplicationSerializer from './application';
export default ApplicationSerializer.extend(DS.EmbeddedRecordsMixin, {
attrs: {
document: {
embedded: 'always'
},
origin: {
embedded: 'always'
},
}
});
//app/serializers/document.js
import DS from 'ember-data';
import ApplicationSerializer from './application';
export default ApplicationSerializer.extend({
});
//app/serializers/origin.js
import DS from 'ember-data';
import ApplicationSerializer from './application';
export default ApplicationSerializer.extend({
});
But I’m still getting the error: Assertion Failed: You can no longer pass a modelClass as the first argument to store.buildInternalModel. Pass modelName instead.
When I remove the belongsTo relationships, it works correctly. So I think there’s something that I’m missing when overriding the RESTSerializer. Here’s the normaized response that is returned from normalizeSingleResponse:
{
data: {
id: "7",
attributes: {
number: '21321321',
protocolDate: 'Mon Sep 25 2017 06:00:00 GMT-0300 (BRT)'
},
relationships:
{
document: {
data: {
id: "2",
numero: "2312312",
}
},
origin: {
data: {
id: "2",
numero: "2312312",
}
}
}
}
}
I’m not sure why the normalized respose is being returned correctly but it doesn’t work pushed into the store. Any clue?
Thanks in advance!