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

Model.save: handle response data or return data in save callback #236

Closed
whitecolor opened this Issue Jan 16, 2013 · 1 comment

Comments

Projects
None yet
2 participants
@whitecolor
Contributor

whitecolor commented Jan 16, 2013

Now Model.save only handle returned id field for newly created instances and assigns id field of current model instance with incoming data.

Why not handle other data then _id and if field in response is model attribute then extend (replace current attribute value) model instance with incoming data?

Case:
Model has children array that is added in web app. On server on a server each child is assigned with id, even if this ids will come response data, in front app children still won't have them. The only way to implement it to fully rewrite save method.

At least it would be better if save method returned server response as second argument of save callback to allow further actions with that data, without need of full overriding of model.save method.

@justinbmeyer

This comment has been minimized.

Show comment
Hide comment
@justinbmeyer

justinbmeyer Sep 20, 2013

Contributor

I think model already adds any other properties. Unfortunately, only jQuery's deferred seems to support multiple arguments when resolving. But, you can overwrite created or destroyed and get access to the jqXHR object:

https://github.com/bitovi/canjs/blob/master/model/model.js#L107

can.Model.extend({
  created: function(data, jqXHR){
    this // -> created instance
  }
})
Contributor

justinbmeyer commented Sep 20, 2013

I think model already adds any other properties. Unfortunately, only jQuery's deferred seems to support multiple arguments when resolving. But, you can overwrite created or destroyed and get access to the jqXHR object:

https://github.com/bitovi/canjs/blob/master/model/model.js#L107

can.Model.extend({
  created: function(data, jqXHR){
    this // -> created instance
  }
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment