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

Fix for ignored {parse: false} on save #2551

Closed
wants to merge 1 commit into from

Conversation

tgriesser
Copy link
Collaborator

If {parse: false} is passed in the options during a save, the model should not attempt to parse the response after the save completes.

@braddunbar
Copy link
Collaborator

Hey Tim! #2456 is very similar regarding Model#fetch, not sure if you saw it, and I have the same question here I guess. Why would you want to skip parsing server data?

@tgriesser
Copy link
Collaborator Author

Because on the initial model fetch, there are bunch of associated models/collections that i've stripped off in parse and placed directly on the model, so I don't really want to run that parse again. After the save it's only returning back the data associate with the model's attributes, excluding all related items.

@tgriesser
Copy link
Collaborator Author

It makes sense that you'd want to keep the server stuff parsed... I'm going to come up with a different solution for handling the relations, etc.

@tgriesser tgriesser closed this May 21, 2013
@ediblecode
Copy link

Hi, I've just come across this. In answer to the question 'Why would you want to skip parsing server data?', I have a use-case: I'm calling save() with {parse: false} as the options because on an update (push) request, the server set-up I'm working with responds with something like {"isValid":true,"errors":[],"data":null} and not the model data. I can't change the server set-up and obviously don't want these properties set on my model so not parsing the response is pretty useful.

@jashkenas
Copy link
Owner

That's a great use case for parsing. Use a parse function to filter out those (expected, but invalid) properties from the response.

@ediblecode
Copy link

Ah yes, great shout, thanks Jeremy.

@fantactuka
Copy link
Contributor

Comments above Model#save says:

// After a successful server-side save, the client is (optionally)
// updated with the server-side state.

while there's no option to prevent server response from being merged into model.

Going back to { parse: false } in model's save, it's still possible to do

parse: function(json, options) {
  if (!options.parse) {
    return;
  }
}

but it looks strange that method should check whether it should have been called or not.

I'd say parse option should be checked before parse method is being called + there should be a way to prevent server response being merged into model's attributes (e.g. merge: false option or smth similar).

@tgriesser tgriesser deleted the parse-model branch March 4, 2014 13:14
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

Successfully merging this pull request may close these issues.

None yet

5 participants