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

Have this.store.pushPayload(type, payload) return records #3576

Closed
bcardarella opened this issue Jul 23, 2015 · 9 comments
Closed

Have this.store.pushPayload(type, payload) return records #3576

bcardarella opened this issue Jul 23, 2015 · 9 comments

Comments

@bcardarella
Copy link
Contributor

It would be a nice convenience if pushPayload returned the resulting records. Otherwise we have to go through the manual process of normalizing the payload and using this.store.push

@bcardarella
Copy link
Contributor Author

Here is a bit more about my use case:

We are using torii for authentication. In the torri adapter we make a $.get request to our backend's sessions endpoint. The response comes back in the json-api format. The torii adapter needs to return the account model as the currentUser to indicate the authenticated state. We get the raw payload as the response from the server so we need a way to deserialize/normalize that data, get it into the store, and retrieve the record for telling torii that this is the currentUser.

this.store.push will return the record as we need but we have to go through the overhead of something like:

let modelClass = this.store.modelFor('account');
let serializer = this.store.serializerFor('account');
let normalizedPayload = serializer.normalizeSingleResponse(this.store, modelClass, payload, null, true);
let account = this.store.push(normalizedPayload);

this.store.pushPayload will encapsulate all of that overhead but does not return any record:

let account = this.store.pushPayload('account', payload);
account === undefined

If it is not desirable to break the current API (as this request would) then could we get some other convenience function to handle this use case?

@wecc
Copy link
Contributor

wecc commented Jul 29, 2015

This and #3576 #3605 seem very related.

Edit: #fail

@workmanw
Copy link

workmanw commented Jan 5, 2016

Bump. It seems odd to me that store.push returns "{DS.Model|Array} the record(s) that was created or updated." while store.pushPayload doesn't.

Looking at the code, it seems easy enough to update the store and serializers. Would a PR be accepted to fix this?

@karellm
Copy link

karellm commented Jan 21, 2016

We ran into the same problem couple times in our app. It would be a really appreciated addition!

@sly7-7
Copy link
Contributor

sly7-7 commented Feb 10, 2016

Closing since the PR was merged

@sly7-7 sly7-7 closed this as completed Feb 10, 2016
@pangratz
Copy link
Member

pangratz commented Aug 1, 2016

Cross-Linking to RFC#161, which addresses the problem raised in this issue.

@bbansalWolfPack
Copy link

any updates on this? facing the same issue because pushPayload does not return anything back. So how can I use normalized response?

@runspired
Copy link
Contributor

@bbansalWolfPack we decided not to move forward with pushPayload return. We intend on deprecating pushPayload, and will eventually introduce an improved push API.

@jagthedrummer
Copy link
Contributor

As best I can tell this seems to the currently suggested approach: https://www.emberjs.com/blog/2018/04/13/ember-3-1-released.html#toc_feature-flag-code-ds-pushpayload-return-code-4-of-4

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

9 participants