Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Backbone.js: stage new model without saving

Is there a way in backbone.js to set up a new model (i.e. instantiate the class with empty attributes), without saving it back to the server?

Specifically, I have a collection which contains several items. When I want to create a new item within my collection, I call collection.create {}. This automatically saves the empty model back to my database.

In Rails, there's a difference between Class.create, which actually creates a database record, and Class.new, which simply creates one in memory and has to be manually saved. I'm basically looking for a backbone equivalent.

like image 916
Kevin Whitaker Avatar asked Mar 10 '12 16:03

Kevin Whitaker


1 Answers

Instead of Collection.create, use Collection.add.

like image 87
Edward M Smith Avatar answered Oct 05 '22 07:10

Edward M Smith