getoutreach / epf

A framework for keeping your Ember.js apps in sync.
http://epf.io
MIT License
369 stars 33 forks source link

Assertion failed: Cannot call get with 'typeKey' on an undefined object. #108

Closed g13013 closed 10 years ago

g13013 commented 10 years ago

I have this error in version 0.1.4 but not in 0.1.3 ! any suggestions

Assertion failed: Cannot call get with 'typeKey' on an undefined object.

ghempton commented 10 years ago

That generally happens when you use the wrong string representation of a type, e.g.: Ep.hasMany('comments') instead of Ep.hasMany('comment'). Can you share some more code?

g13013 commented 10 years ago

user json

{
    "user": {
        "id": 1,
        "first_name": "Aboubakr",
        "last_name": "Gasmi",
        "birthday": "10/02/1983",
        "age":"28"
    }
}
App.User = Ep.Model.extend({

    firstName: Ep.attr('string'),

    lastName: Ep.attr('string'),

    birthday: Ep.attr('string'),

    age: Ep.attr('number')//,

    // //RELATIONS
    // gender: Ep.belongsTo('gender'),

    // maritalStatus: Ep.belongsTo('maritalStatus'),

    // address: Ep.belongsTo('addresss'),

    // emails: Ep.hasMany('email'),

    // socialAccounts: Ep.hasMany('socialAccount'),

    // cvs: Ep.hasMany('cv')

});

At first I thought it wat a probelem with relationshipt so I commented them but still have the error

jimsynz commented 10 years ago

Okay, so digging into my stack trace I am seeing something pretty weird.

Inside Ep.Session#load there's the following promise:

                return Ep.resolveModel(this.adapter.load(type, id).then(function (model) {
                    return session.merge(model);
                }, function (model) {
                    throw session.merge(model);
                }), type, id, session);

Looking at the failure, I see that model is set to TypeError {}: "Object [object Object] has no method 'deserializePayload'". No wonder session.merge is getting freaky.

ghempton commented 10 years ago

Sorry for the delay, this totally fell off my radar. I think that the issue here is that the type isn't resolving correctly from the hasMany macros. Try Ep.belongsTo('social_account') (instead of the camel cased version).

ghempton commented 10 years ago

I am going to close this issue, let me know if my solution hasn't fixed it.

tygriffin commented 9 years ago

I'm having the same problem in 0.3.5

Genkilabs commented 9 years ago

+1. I made a very vanilla single-file app based on the ember starter kit which his a Rails API:

//app.js
App = Ember.Application.create({
    LOG_TRANSITIONS: true,
    LOG_BINDINGS: true,
    LOG_ACTIVE_GENERATION: true,
    LOG_VIEW_LOOKUPS: true,
});

App.Store = Ep.RestAdapter.reopen({
    host: 'http://localhost:3000'
});

App.Agent = Ep.Model.extend({
    last_name: Ep.attr('string')  
});

App.IndexRoute = Ember.Route.extend({
    model: function() {
        // return ['red', 'yellow', 'blue'];
        return this.session.query('agent');
    }
});
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Ember Starter Kit</title>
  <link rel="stylesheet" href="css/normalize.css">
  <link rel="stylesheet" href="css/style.css">
</head>
<body>
  <script type="text/x-handlebars">
    <h2>Welcome to Ember.js</h2>

    {{outlet}}
  </script>

  <script type="text/x-handlebars" id="index">
    Agents
    <ul>
    {{#each item in model}}
      <li>Agent: {{!last_name}}</li>
    {{/each}}
    </ul>
  </script>

  <script src="js/libs/jquery-1.10.2.js"></script>
  <script src="js/libs/handlebars-1.1.2.js"></script>
  <script src="js/libs/ember-1.7.0.js"></script>
  <script src="js/libs/epf-0.3.5.js"></script>
  <script src="js/app.js"></script>
  <!-- to activate the test runner, add the "?test" query string parameter -->
  <script src="tests/runner.js"></script>
</body>
</html>

Localhost:3000/agents.json returns something like

{
  "agents": [
    {
      "id": 2260,
      "first_name": "Mike",
      "last_name": "Johnsom"
    },
    ....
  ]
}

And the error: Error while processing route: index Assertion Failed: Cannot call get with 'typeKey' on an undefined object. Error: Assertion Failed: Cannot call get with 'typeKey' on an undefined object. at new Error (native) at Error.EmberError (file:///Users/Gingitsune/Development/vanilla_epf/js/libs/ember-1.7.0.js:13538:23) at Object.Ember.assert (file:///Users/Gingitsune/Development/vanilla_epf/js/libs/ember-1.7.0.js:3722:15) at get (file:///Users/Gingitsune/Development/vanilla_epf/js/libs/ember-1.7.0.js:16677:13) at exports.default.Ember.Object.extend.updateParents (file:///Users/Gingitsune/Development/vanilla_epf/js/libs/epf-0.3.5.js:4442:23) at exports.default.Adapter.extend.willMergeModel (file:///Users/Gingitsune/Development/vanilla_epf/js/libs/epf-0.3.5.js:5290:31) at apply (file:///Users/Gingitsune/Development/vanilla_epf/js/libs/ember-1.7.0.js:18380:27) at superWrapper as willMergeModel at Session.reopen.merge (file:///Users/Gingitsune/Development/vanilla_epf/js/libs/epf-0.3.5.js:6840:17) at merge (file:///Users/Gingitsune/Development/vanilla_epf/js/libs/epf-0.3.5.js:5202:28) ember-1.7.0.js:14463

Any thoughts? Prior to 0.3.5 what is the best stable build to dev with?

Genkilabs commented 9 years ago

Ungh... It turns out that reopening the RESTAdapter and changing the host sends the request as HTML instead of JSON. My Rails back end was rendering HTML, just like it was asked, and that is the error which results. Hope this explanation helps someone else out tho...

NOT A BUG