0

after I change to Backbone-Relational my model stopped to work when I call destroy().. I have to ensure that when it removes success on server there will be no more id at client side, so then when I try to save it again my model wont request PUT (update) - throws Record Not Found on server side.

Coffeescript side

save: ->        
    if isBlank @model.get("text")
        @model.destroy() # after success it still with same attributes including id!!
    else
        @model.save()

Rails side

def destroy
    @note = Note.find(params[:id])
    @note.destroy        
    respond_with @note # callback is empty
end

Bug from Backbone-Relational perhaps? Does Backbone.js update id after destroy?

mateusmaso
  • 7,843
  • 6
  • 41
  • 54

1 Answers1

0

Backbone does not look like it modifies the Model on destruction in any way. Except removing it from its collection if any.

Check the code

What it does is triggering the event destroy so you easily can listen this event and do whatever you think is the proper behavior in destruction:

// code simplified and no tested
var MyModel = Backbone.Model.extend({
  initialize: function(){
     this.on( "destroy", this.afterDestroy, this );
  },

  afterDestroy: function(){
    this.set( "id", null );
  }
});
fguillen
  • 36,125
  • 23
  • 149
  • 210