-
-
Notifications
You must be signed in to change notification settings - Fork 136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
findRecord giving error "Cannot read property '_internalModel' of undefined" #136
Comments
This issue is missing a few key details @swatijadhav.
|
item model: import Ember from 'ember'; import DS from 'ember-data'; var attr = DS.attr, belongsTo = DS.belongsTo; export default DS.Model.extend({ donorDescription: attr('string'), state: attr('string'), offer: belongsTo('offer', { async: false }) }) item factory: import FactoryGuy from 'ember-data-factory-guy'; import './offer'; FactoryGuy.define('item', { sequences: { id: function(num) { return num + 100; }, description: function(num) { return 'Donor Description' + num; } }, default: { id: FactoryGuy.generate('id'), state: 'submitted', donorDescription: FactoryGuy.generate("description"), }, }); export default {}; test case: import Ember from 'ember'; import startApp from '../helpers/start-app'; import syncDataStub from '../helpers/empty-sync-data-stub'; import FactoryGuy from 'ember-data-factory-guy'; import TestHelper from 'ember-data-factory-guy/factory-guy-test-helper'; var App, store, offer1, item1; module('Donor: Display Item Status', { setup: function() { App = startApp(); TestHelper.setup(); store = TestHelper.getStore(); syncDataStub(TestHelper); offer1 = FactoryGuy.make("offer", {state:"submitted"}); item1 = FactoryGuy.make("item", {offer: offer1, state:"submitted"}); }, teardown: function() { Em.run(function() { TestHelper.teardown(); }); Ember.run(App, 'destroy'); } }); test("Display item status for submitted item", function() { visit('/offers/' + offer1.id + "/items/"+ item1.id +"/messages"); andThen(function() { equal(currentURL(), '/offers/' + offer1.id + "/items/"+ item1.id +"/messages"); equal($.trim(find('.status-message').text()), "This item is awaiting review."); }); }); |
While inspecting further, came to know that in
this value is evaluated as false. For the same /** This is a helper method that always returns a JSON-API Document. If the current serializer has `isNewSerializerAPI` set to `true` this helper calls `normalizeResponse` instead of `extract`. All the built-in serializers get `isNewSerializerAPI` set to `true` automatically if the feature flag is enabled. So I added it export default ActiveModelAdapter.extend({ isNewSerializerAPI: true, But still facing same issue. |
do me a favour and do this:
for your test ( get rid of the id line ) .. |
Thanks for the response @danielspaniel |
@swatijadhav ... can you send me your router code too .. curious also curious to see what you get for:
like what the store is returning? check network. should not be doing network call .. should go to store and get the item ( assuming you have the right id .. which you should base on your test ) |
then right after your test code here:
|
In this.resource('offers', function () { this.resource('offer', { path: '/:offer_id'}, function() { this.resource('item', {path: '/items/:item_id'}, function() { this.route('index', { path: '/'}); }); }); }); |
yes, it gets 'item1._internalModel' value
|
what about this one:
what do you get for those console statements |
|
hmm .. 4 is odd .. should be 1, but the rest is good |
the count is 4 because we have created some more data for other test cases in same file.. so we can neglect that
|
ok .. so replace
with
|
though what is really troubling me is that there should not be a payload at all .. since it should be getting the item from the store and returning that one. so I am wondering if you get any network calls when you run this test ( developer tools on chrome .. network tab ) |
because if there is an error here:
that means the store went and did an ajax find to get the json .. odd .. isn't it? |
|
that is super interesting .. well .. is there a network call? |
Check this issue emberjs/data#3757 |
hmm .. fascinating .. that should not be happening .. and good find there from ember-data ticket |
any workaround for this issue? any suggestions? |
hmm .. I guess that concept of preloading the store might be unreliable.
|
|
though your default is state ( submitted ) for offers and items .. so that might seem redundant .. but I think you know what I mean .. right? |
yeah, got your point.. |
Finally got the exact cause: In my adapter/application.js
These lines I had added while fixing deprecation warnings, and because of this, it was causing records to be loaded always, although they were present in ember-data store. So now I just removed those. Thank you very much for all the help.. 😄 |
great news @swatijadhav .. really happy you are back in business, and I am glad you posted this to help others with similar problem |
Thanks 👍 |
Getting this error "Cannot read property '_internalModel' of undefined" on |
huh? .. what you talkin bout willis? |
Here is my application adapter :
Here is the application serializer:
Error stack trace: |
sorry ... I have no idea what you are talking about .. too little info |
what do you want me to give you? Here is the code snippet which throws this error |
so .. pretend you were me and this is all you had to look at .. you tell me how you would fix it? cause if you could .. maybe you are some kind of genius and I will bow before you. |
what more information you want me to give you ? can you specify that ? |
no .. I want you to figure it out alittle bit .. because you don't seem to be able to understand what it is like for me .. so think more about it |
In our ember app, we are using following versions of ember-data and ember-data-factory-guy.
package.json
Note: we are using active-model adapter, not yet migrated to the json-api adapter.
Route: item.js
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:
ember-data/lib/system/stpre/finder.js, fails at
return
statement(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.
The text was updated successfully, but these errors were encountered: