-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Add a method for normalizing a payload instead of a single resource #3605
Comments
I think I just hit the same thing you described—it looks like I was sort of able to get this to work as a workaround, though with a bunch of deprecation warnings: var userId = payload.data.id; // Grab now because pushPayload modifies the hash.
store.pushPayload(payload);
var userRecord = store.peekRecord('user', userId); To fix this, shouldn't |
Just for the record, |
Ah makes sense—let me reframe then, shouldn't I'd expect this to work: |
I'd say that's exactly the issue :) |
Hah got it—after that and reading a bunch of the ember-data source, I see now that the OP was asking for exactly that all along. :) A |
Closing, since #3838 was closed too, and if I understand well, store.pushPayload() (with the |
@sly7-7 Looks good to me. Thanks for checking up on this issue. |
I am building a Service that takes care of authenticating a user in my application. The Service does a request to the API, normalizes the data, pushes and gets the record from the store and resolves with said record of an authenticated user.
The issue I am encountering is that there is no way to normalize the payload without manually stripping the
data
hash from the root of the server response. This is becausestore.normalize()
accepts only a single resource and not a payload like JSON API where the type and primary data is known. The Service now needs to know what the format of the payload is because the API response needs to be modified, which means that if the API response changes this code will break.After some discussion with @wecc and @igorT a suggestion popped up that it might be an idea to add a
normalizePayload
method which should take an optionalmodelName
parameter to determine which serializer will be used and ainputPayload
argument to pass the payload (much the same as store.pushPayload).Current situation:
Proposed solution:
The text was updated successfully, but these errors were encountered: