ember.js - How to update an existing record when creating a record with ember-data -
ember.js - How to update an existing record when creating a record with ember-data -
when seek create model instance
record = this.store.createrecord('model', { /* whatever */ }); record.save();
and api updates existing backend record instead of creating new one. api returns http 200 [ok] (could 202 [accepted]) instead of 201 [created]. ember way have record not created in store if instance of same record there?
right if "create" record turns out update existing record x times, end having same record (with same id) repeated x times in ember-data store.
when utilize createrecord, you're telling ember add together new record store.
you need fetch record store first, if want update it:
this.store.find('model', id).then(function(record) { record.set('property', 'value'); record.save(); });
http://emberjs.com/api/data/classes/ds.store.html#method_createrecord
maybe you're looking this.store.update( ... ), depending on specific needs: http://emberjs.com/api/data/classes/ds.store.html#method_update
ember.js persistence ember-data
Comments
Post a Comment