FindRecord giving the error "Unable to read _internalModel 'property from undefined"

In our ember application, we use the 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 an active model adapter that has not yet been ported 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); } }); 

It works fine in development mode , but during test cases, the following problem occurs:

The test case for "displaying a single item" fails with the following error:

 { "message": "Cannot read property '_internalModel' of undefined", "name": "TypeError" } 

ember-data / lib / system / stpre / finder.js does not work in return statement

return prom.then (function (adapterPayload) {Ember.assert ("You made a request for" + typeClass.typeClassKey + "with the identifier" + id + ", but the adapter response did not contain 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 something? Can someone help me solve this problem? I tried to upgrade to the latest versions, but still ran into the same problem.

+6
source share
4 answers

In my case, the problem was that there was no root element in the server response.

The server returned for the user:

 { surname: 'surname', name: 'name', _id: 56ead1ace85b04be4a7e50e6 } 

instead:

 user: { surname: 'surname', name: 'name', _id: 56ead1ace85b04be4a7e50e6 } 
+2
source

If you request a server using findRecord() , Ember expects a response in the form

 {singularModelName: {...}} 

If you request a server using query() , Ember expects the response to be in the form

 {pluralModelName: [...]} 

A type error will occur if you do not follow this response pattern when using findRecord()

+2
source

Basically, I write it here as a reminder for myself. I come across this question every two weeks and come here to find the answer :)

This error occurred when I ran the acceptance tests because I forgot to tell ember-cli-mirage to create fake models:

 beforeEach(function() { server.create('user', { id: window.sessionUser.id }); server.create('project', { userId: window.sessionUser.id }); }); 
+1
source

Finally got the exact reason:

In my adapter /application.js

 // Ember Data 2.0 Reload behavior shouldReloadRecord: function() { return true; }, shouldReloadAll: function() { return true; }, shouldBackgroundReloadRecord: function() { return true; }, shouldBackgroundReloadAll: function() { return true; }, 

I added these lines when setting the obsolescence warnings, and because of this, he always loaded the records, although they were present in the ember-data data warehouse. Now I just deleted them.

http://emberjs.com/blog/2015/06/18/ember-data-1-13-released.html#toc_new-adapter-hooks-for-better-caching This link helped me understand it better :)

0
source

All Articles