AnsweredAssumed Answered

model.save best practices

Question asked by Richard Coleman on Feb 7, 2018
Latest reply on Feb 8, 2018 by Richard Coleman

Hi All,

 

Just a quick question here about Sidecar's save() function.

 

I'm effectively doing the following via Sidecar:

var accountBean = app.data.createBean("Accounts", { id: this.model.get("billing_account_id") });

accountBean.fetch();

 

I then (assuming the conditions are correct), want to update one field, and report success to the user.

 

I've seen two ways of doing this, and I wondered which was considered the "best practice".

 

The most frequently seen Sugar way (passing the whole model back through)

accountBean.set("account_type","Customer");
accountBean.save({ {},{
    success : function(account){
        //code here
    }
}

Or the way documented on backbone.js where only changed properties are sent through:

accountBean.save({ {"account_type":"Customer"},{
    success : function(account){
        //code here
    }
}

 

Is there any benefit to doing either way? Any big problems with either way?

Outcomes