Create temporary non-resident object in Ember-Data

I want to create an object using ember-data, but I do not want to save it until I name commit. How can I achieve this behavior?

+7
source share
3 answers

You can use the transaction defined by transaction.js with the corresponding tests in transaction_test.js .

See an example here :

 App.store = DS.Store.create(...); App.User = DS.Model.extend({ name: DS.attr('string') }); var transaction = App.store.transaction(); transaction.createRecord(App.User, { name: 'tobias' }); App.store.commit(); // does not invoke commit transaction.commit(); // commit on store is invoked​ 
+4
source

Call createModel instead!

Example:

 // This is a persisted object (will be saved upon commit) var persisted = App.store.createRecord(App.Person, { name: "Brohuda" }); // This one is not associated to a store so it will not var notPersisted = App.store.createModel(App.Person, { name: "Yehuda" }); 

I made for this http://jsfiddle.net/Qpkz5/269/ .

+1
source

You can use _create : App.MyModel._create() - it will associate the model with its own state manager, so App.store.commit() will not do anything.

However, _create "private". I think there should be a public method for this use case.

0
source

All Articles