ember.js - cannot delete record which hasMany relationship to same record type (ember data 1.0.0-beta.9) -
i upgraded ember data 1.0.0-beta.2 ember data 1.0.0-beta.9. there piece of code delete record works fine in beta 2, doesn't work in beta.9
my model looks this:
as.question = ds.model.extend({ questionname: ds.attr('string'), childquestions: ds.hasmany('question', { async: true }) });
and delete method looks this:
deletequestion: function (question) { var self = this; question.deleterecord(); question.save().then(function () { console.log('success'); //unload child records store because server removes child questions }, function (failureresponse) { console.log(failureresponse); console.log('failure'); //perform rollback })['finally'](function () { console.log('in finally'); }); }
in ember data beta 9, never goes through success function if question has child questions, goes second function catches failure. delete works if question not have child questions. tried deleting child questions first before deleting parent question model still goes directly failure block. delete request resolves correctly http status 200 , response delete request empty object {}.
the "failureresponse" coughs out :
error: assertion failed: calling set on destroyed object @ new error (native) @ error.embererror (lib/ember/ember.js:13538:33) @ object.ember.assert (lib/ember/ember.js:3722:27) @ set (lib/ember/ember.js:16834:23) @ ember.object.extend.hasmanydidchange (lib/ember/ember-data.js:7112:11) @ null.<anonymous> (lib/ember/ember-data.js:7101:18) @ lib/ember/ember.js:14897:34 @ object.orderedset.foreach (lib/ember/ember.js:14739:28) @ object.map.foreach (lib/ember/ember.js:14895:26) @ ember.object.extend.reloadhasmanys (lib/ember/ember-data.js:7098:23)
it must have been caused :
hasmanydidchange: function(key) { var hasmany = this._relationships[key]; if (hasmany) { var records = this._data[key] || []; set(hasmany, 'content', ember.a(records));//one of these sets in ember-data set(hasmany, 'isloaded', true); hasmany.trigger('didload'); } },
any idea how can make delete work in beta release? if know how create fake server create jsbin - tried using sinon couldn't make things work.
regards, dee
update: issue must caused else, since couldn't recreate issue here : http://jsbin.com/yofuqa/2/ still weird same logic work in beta 2 not in beta 9!
with beta .11, hasmany relation not load. here jsbin: http://jsbin.com/yofuqa/3/
Comments
Post a Comment