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

collection.create does not return a jqXHR #1155

Closed
braddunbar opened this issue Mar 29, 2012 · 3 comments
Closed

collection.create does not return a jqXHR #1155

braddunbar opened this issue Mar 29, 2012 · 3 comments

Comments

@braddunbar
Copy link
Collaborator

I made a mistake in #1111 and documented that collection.create returns a jqXHR. I've just noticed, however, that it does not. It returns the created model.

However, this seems incorrect to me. it seems out of place compared to the other persistence methods. Furthermore, the jqXHR is not accessible in any way and thus there is no way to observe the outcome of the request.

As for a reference to the model, there are several scenarios:

  1. {wait: true}, success - the model is added to the collection.
  2. {wait: true}, failure - there is no need for a reference to the model.
  3. {wait: false}, success - the model was added to the collection.
  4. {wait: false}, failure - the model was added to the collection.

Case number 4 is a bit problematic, but could be easily circumvented by removing the model on a failed request with {wait: false}.

Thoughts?

@lfac-pt
Copy link

lfac-pt commented Mar 30, 2012

Yes! A easy way to access the jqXHR object would be most useful.

@jashkenas
Copy link
Owner

I'm afraid that create is intended to return a reference to the model. If you want the jqXHR -- add the model by hand instead.

As to the semantics of the failure cases ... I think they're valid. You may have a reference to a model that was unable to be added to the server, in the same way you can do this:

var model = new Model(attrs);
model.save();

... and have a reference to a model that was unable to be saved to the server.

@braddunbar
Copy link
Collaborator Author

Fair enough.

I agree that it's ok to have a reference to a model who failed to persist. I just want to know if it failed or succeeded. One can use the success and error callbacks, but their semantics differ slightly from the jqXHR and it's not possible to pass them around and piggyback on through .done(...) and .fail(...).

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

3 participants