Skip to content

Model.destroy() errors out in Backbone.sync #1

@sderickson

Description

@sderickson

TypeError: Cannot read property 'wait' of undefined
at Object.options.success (http://localhost:3000/javascripts/vendor.js:14850:20)
at UserState.Backbone.sync (http://localhost:3000/javascripts/vendor.js:30692:20)
at UserState..extend.sync (http://localhost:3000/javascripts/vendor.js:14627:28)
at UserState.
.extend.destroy (http://localhost:3000/javascripts/vendor.js:14859:22)
...

The problem appears to be the replaced Backbone.sync function:

Backbone.sync = (method, model, options) ->

Call options.success() callback to trigger destroy event which triggers

synchronization to other browsers.

if method is "delete"
options.success()

And that goes to this function wrapper in Backbone 0.9.10:

  options.success = function(model, resp, options) {
    if (options.wait || model.isNew()) destroy();
    if (success) success(model, resp, options);
  };

Since no parameters are passed to options.success(), options is undefined and options.wait throws an error (as would model.isNew if given the chance).

Changing that line to:

options.success(model, null, options)

Seems to do the trick. Now destroy() doesn't error out for me.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions