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

Resource actions .then() returning undefined #12

Closed
rossanthony opened this issue Feb 24, 2017 · 2 comments
Closed

Resource actions .then() returning undefined #12

rossanthony opened this issue Feb 24, 2017 · 2 comments

Comments

@rossanthony
Copy link

rossanthony commented Feb 24, 2017

I have a resourceAction defined on one of my models called 'workflow' like so:

default: resourceAction('default', { pushToStore: true, type: 'POST', promiseType: null }),

Essentially in our API we have an endpoint POST /workflows/default which when posted to with minimal required values will create a new 'workflow' based on some defaults they have saved.

However when trying the following...

let emptyWorkflow = this.get('store').createRecord('workflow');

emptyWorkflow.default(payload).then((workflow) => {
    console.log('default wf created:', workflow); // << 'workflow' is undefined here!
}).finally(()=>{
    emptyWorkflow.deleteRecord();
});

...nothing seems to be passed through to the .then the workflow param is undefined.

The backend does create the item though and responds with the attributes. I can also see via Ember inspector that the new 'workflow' is added to the store, however I'd like to get it's ID at the point of the console.log in the above example so I can transition to it.

I also tried setting the option pushToStore: false, then I get an object containing the backend API's response payload. Is it possible to get the actual Ember model object for the newly created item passed through to the .then()?

@rossanthony
Copy link
Author

Sorry my fault... I had a separate serializer defined for the model concerned. So while my main application serializer was using import { JSONAPISerializer } from 'ember-custom-actions' the one specific to the model was still using the default Ember data JSONAPISerializer.

@Exelord
Copy link
Member

Exelord commented Feb 24, 2017

In the future, the serializer won't be needed. But for now... :/ sorry...
I'm still waiting for this RFC emberjs/rfcs#161

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

No branches or pull requests

2 participants