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 doesn't trigger error if {wait: true} #1845

Closed
rinatio opened this Issue Nov 27, 2012 · 6 comments

Comments

Projects
None yet
4 participants
@rinatio

rinatio commented Nov 27, 2012

Hello guys, thank you for this awesome library!

Have a question: when i do collection.create({name: 'Name'}, {wait: true}), if server returns a 400 response error won't be triggered on collection level. I understand that it happens because you attach _onModelEvent on success. Is it by design? Is there some workaround except passing error option in create?

Thanks

@jashkenas

This comment has been minimized.

Show comment
Hide comment
@jashkenas

jashkenas Nov 28, 2012

Owner

Yes, I'm afraid that if create fails, there is no such model in the collection at any time, so the collection won't have the error. I think that makes logical sense. It would be strange for a collection to fire an error event for a model that it doesn't contain. I'd use the error callback in this case.

Owner

jashkenas commented Nov 28, 2012

Yes, I'm afraid that if create fails, there is no such model in the collection at any time, so the collection won't have the error. I think that makes logical sense. It would be strange for a collection to fire an error event for a model that it doesn't contain. I'd use the error callback in this case.

@jashkenas jashkenas closed this Nov 28, 2012

@rinatio

This comment has been minimized.

Show comment
Hide comment
@rinatio

rinatio Nov 28, 2012

The fact is, however, that it works without {wait: true} :) Since you add model to collection before ajax request )

rinatio commented Nov 28, 2012

The fact is, however, that it works without {wait: true} :) Since you add model to collection before ajax request )

@jashkenas

This comment has been minimized.

Show comment
Hide comment
@jashkenas

jashkenas Nov 28, 2012

Owner

Right, exactly. In that case the model is in the collection.

Owner

jashkenas commented Nov 28, 2012

Right, exactly. In that case the model is in the collection.

@rinatio

This comment has been minimized.

Show comment
Hide comment
@rinatio

rinatio Nov 28, 2012

Okay, thank you @jashkenas

rinatio commented Nov 28, 2012

Okay, thank you @jashkenas

@caeost

This comment has been minimized.

Show comment
Hide comment
@caeost

caeost Aug 2, 2013

Hi @jashkenas is this also the same reason why if validate() signals an error during create and "wait" is true, the "invalid" event is not propagated to the collection? It appears to fail silently from the collection's point of view as in: http://jsbin.com/iruvoy/6/edit

caeost commented Aug 2, 2013

Hi @jashkenas is this also the same reason why if validate() signals an error during create and "wait" is true, the "invalid" event is not propagated to the collection? It appears to fail silently from the collection's point of view as in: http://jsbin.com/iruvoy/6/edit

@mmrko

This comment has been minimized.

Show comment
Hide comment
@mmrko

mmrko Jun 30, 2015

@caeost I ran into the same issue. I resorted to the following workaround for my use case:

var collection  = new Backbone.Collection();
var model = collection.create(data, { wait: true });

if (model.validationError) {
  // ...
}

mmrko commented Jun 30, 2015

@caeost I ran into the same issue. I resorted to the following workaround for my use case:

var collection  = new Backbone.Collection();
var model = collection.create(data, { wait: true });

if (model.validationError) {
  // ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment