@braddunbar : When passing {wait: true} as option to the create method of a Supermodel or to the create method of an association collection, the option is not respected. The new model instance is created and will be added to the all() collections immediately.
Is this on purpose to be in line with the change of Backbone being optimistic about saves? Added success and error callbacks are called and it's easily possible to remove a model again using the following error callback:
error: function(model) {
model.destroy();
}
But since views might be listening to events on a collection this would lead to the new model's view being rendered, just to be removed shortly afterwards in case of a failed save-attempt. (This is how it is in my case)
One way to solve this is to move the following code out of the initialize function and into it's own:
// Add the model to `all` for each constructor in its prototype chain.
var ctor = this.constructor;
do { ctor.all().add(this); } while (ctor = ctor.parent);
// Trigger 'initialize' for listening associations.
this.trigger('initialize', this);
This way we could check if the wait option is set and then just wrap the passed success callback in a function, which would first add the now saved model to the all() collections and after that trigger the initialize event.
Let me know what you think about this and I would be happy to create a pull request!
@braddunbar : When passing
{wait: true}
as option to thecreate
method of a Supermodel or to thecreate
method of an association collection, the option is not respected. The new model instance is created and will be added to theall()
collections immediately.Is this on purpose to be in line with the change of Backbone being optimistic about saves? Added
success
anderror
callbacks are called and it's easily possible to remove a model again using the following error callback:But since views might be listening to events on a collection this would lead to the new model's view being rendered, just to be removed shortly afterwards in case of a failed save-attempt. (This is how it is in my case)
One way to solve this is to move the following code out of the
initialize
function and into it's own:This way we could check if the
wait
option is set and then just wrap the passedsuccess
callback in a function, which would first add the now saved model to theall()
collections and after that trigger theinitialize
event.Let me know what you think about this and I would be happy to create a pull request!