Assertion Failed: You can no longer pass a modelClass as the first argument to store.buildInternalModel

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!

What does the API response look like? Maybe you can set up a twiddle?

Hey! Thank you! The API response looks like this:

{
    "primary": {
        "id": "7",
        "protocolDate": "2017-09-25 06:00:00",
        "number": "123213213",
        "document": {
            "id": "2",
            "number": "12321321",
        },
        "origin": {
            "id": "3",
            "number": "Unidade 3"
        }
    }
}

And here’s the twiddle: Ember Twiddle

And here’s the error:

ember.debug.js:19840 Assertion Failed: You can no longer pass a modelClass as the first argument to store.buildInternalModel. Pass modelName instead.
Error
    at assert (http://localhost:4200/assets/vendor.js:23767:13)
    at Object.assert (http://localhost:4200/assets/vendor.js:23980:34)
    at assert (http://localhost:4200/assets/vendor.js:144393:34)
    at Class.buildInternalModel (http://localhost:4200/assets/vendor.js:154826:25)
    at Class._internalModelForId (http://localhost:4200/assets/vendor.js:153560:30)
    at Class._pushResourceIdentifier (http://localhost:4200/assets/vendor.js:154988:19)
    at BelongsToRelationship.updateData (http://localhost:4200/assets/vendor.js:151396:38)
    at BelongsToRelationship.push (http://localhost:4200/assets/vendor.js:152150:14)
    at http://localhost:4200/assets/vendor.js:155075:20
    at http://localhost:4200/assets/vendor.js:147861:18

Could you also add the route code that calls the store? You can use mockjax to set up a fake response, like here: Mockjax Sample · GitHub

Solved! Turns out that I didn’t need to override any methods inside the serializer. I just needed to keep it simple and let Ember take care of things. @skaterdav85 thanks for your help!

1 Like