-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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 should return the request object #2961
Comments
So far the reasoning I see is that "it's intended to return a model" which isn't really a reason in it of itself. Is there a specific use case that necessitates it behaving differently from the others? |
|
but @jashkenas, you could pass a model to var myModel = null;
collection.create({ bla: 12 }).then(function(model) {
myModel = model;
}); An empty non-initialized model is worse than no model, because someone not realizing there is a network operation happening could start using the model before it's actually saved, which may not be the desired behavior. |
You could, but that's not the intended use case. Your code example makes sense, but it's noticeably awkward compared to:
... that's exactly how optimistic models are supposed to be used. If you're worried about the save failing, or the model being invalidated by the server, and so on, then you'll want to
|
Right now the current
create
call returns the model that was created, but that is inconsistent with the waysave
,destroy
andfetch
work. Those all return the xhr object, allowing the use of deferreds in a consistent fashion. Sincecreate
is also a networked operation, it should return the xhr object as well.Is there a reason why
create
returns the model itself? I realize that you can provide a json object at which point you'd need to capture the model instance in the callback, but you could also pass a model directly tocreate
(thus already having the model). At present, I believecreate
is the only api call that requires use of thesuccess
callback if you want to capture the result of the operation.Happy to make a pull req if this is a desired change.
The text was updated successfully, but these errors were encountered: