In our ember app, we are using following versions of ember-data and ember-data-factory-guy.
package.json
"ember-cli": "^1.13.8",
"ember-data": "1.13.9",
"ember-data-factory-guy": "1.13.10",
Note: we are using active-model adapter, not yet migrated to the json-api adapter.
import ActiveModelAdapter from 'active-model-adapter';
export default ActiveModelAdapter.extend({
Route: item.js
export default Ember.Route.extend(({
model(params) {
return this.store.findRecord('item', params.item_id);
}
});
Its working fine in development mode, but while running test cases, am facing following issue:
Test Case for "display single item" fails with following error:
{
"message": "Cannot read property '_internalModel' of undefined",
"name": "TypeError"
}
ember-data/lib/system/stpre/finder.js, fails at return
statement
return promise.then(function (adapterPayload) { Ember.assert("You made a request for a " + typeClass.typeClassKey + " with id " + id + ", but the adapter's response did not have any data", adapterPayload);
return store._adapterRun(function () {
var requestType = get(serializer, 'isNewSerializerAPI') ? 'findRecord' : 'find';
var payload = normalizeResponseHelper(serializer, store, typeClass, adapterPayload, id, requestType);
//TODO Optimize
var record = pushPayload(store, payload);
return record._internalModel;
});
(https://github.com/emberjs/data/blob/master/packages/ember-data/lib/system/store/finders.js#L32)
Are we missing anything here? Can anyone please help me to resolve this? I have tried by upgrading versions to latest, but still facing same issue.
In my case the problem was that the server's response didn't have the root element.
Server was returning for a user:
{
surname: 'surname',
name: 'name',
_id: 56ead1ace85b04be4a7e50e6
}
instead:
user: {
surname: 'surname',
name: 'name',
_id: 56ead1ace85b04be4a7e50e6
}
If you're querying the server using findRecord()
, Ember expects the response to be in the form
{singularModelName: {...}}
If you're querying the server using query()
, Ember expects the response to be in the form
{pluralModelName: [...]}
The type error will occur if you're not following that response pattern while using findRecord()
I mostly post this here as a reminder for myself. I run into this issue every couple weeks and come here to find an answer :)
This error was thrown while I was running acceptance tests because I forgot to tell ember-cli-mirage to generate fake models:
beforeEach(function() {
server.create('user', { id: window.sessionUser.id });
server.create('project', { userId: window.sessionUser.id });
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With