Skip to content
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

Version 1 is failing with No model was found error - Need to implement extractSingle #14

Closed
holandes22 opened this issue Nov 13, 2014 · 3 comments
Labels

Comments

@holandes22
Copy link
Collaborator

Hi,

Finally got some time to investigate a little more. Here is an issue I'm having using the version 1.0 branch.
I get this error when I try to find a user:

"Error: No model was found for 'id'
    at new Error (native)
    at Error.EmberError (http://0.0.0.0:4200/assets/vendor.js:25594:23)
    at Ember.Object.extend.modelFor (http://0.0.0.0:4200/assets/vendor.js:72988:19)
    at __exports__.default.JSONSerialize.extend.extractSingle (http://0.0.0.0:4200/assets/vendor.js:66134:28)
    at apply (http://0.0.0.0:4200/assets/vendor.js:30440:27)
    at superWrapper [as extractSingle] (http://0.0.0.0:4200/assets/vendor.js:30014:15)
    at __exports__.default.Ember.Object.extend.extractFind (http://0.0.0.0:4200/assets/vendor.js:65670:21)
    at __exports__.default.Ember.Object.extend.extract (http://0.0.0.0:4200/assets/vendor.js:65539:37)
    at http://0.0.0.0:4200/assets/vendor.js:73512:34
    at tryCatch (http://0.0.0.0:4200/assets/vendor.js:57874:16)"

ED is using extractSingle method to handle this, because the response is

    {"id": 1, "username": "pp", "email": "pp@pp.com", "full_name": "", "teams": [], "is_staff": true}

But, since it is expecting something like this:

{"user":  {"id": 1, "username": "pp", "email": "pp@pp.com", "full_name": "", "teams": [], "is_staff": true}}

it's assuming the first key is the model type to search for, but of course fails to find one.

Switching to ED beta 11 shows a different error (since it now actually tries with each key before failing), but problem persists.

I tried a solution and it worked for me, which was implementing extractSingle and modify the payload to what ED expects:

  extractSingle: function(store, primaryType, rawPayload, recordId) {                                                                                                           
    var payload = {};                                                                                                                                                           
    payload[primaryType.typeKey] = rawPayload;                                                                                                                                  
    return this._super(store, primaryType, payload, recordId);                                                                                                                  
  }

Overriding normalizedPayload won't work since we don't get passed the type, only the payload.

@dustinfarris @benkonrath do you see any problem with this approach?

@benkonrath
Copy link
Collaborator

@holandes22 Looks good. See my comment in #15.

@dustinfarris dustinfarris added this to the Version 1.0 milestone Nov 18, 2014
@benkonrath
Copy link
Collaborator

@holandes22 This proposed change has also been merged, right?

@holandes22
Copy link
Collaborator Author

Indeed, closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants