Transactions 余烬事务:在事务之间移动对象
我已经实现了一个包含事务的路由。当用户通过单击“后退”按钮退出此路由时,我希望用户能够确认退出并取消回滚事务所做的任何更改 问题在于,如果用户返回路线,则会引发Ember数据并错误地指出:Transactions 余烬事务:在事务之间移动对象,transactions,ember.js,ember-data,Transactions,Ember.js,Ember Data,我已经实现了一个包含事务的路由。当用户通过单击“后退”按钮退出此路由时,我希望用户能够确认退出并取消回滚事务所做的任何更改 问题在于,如果用户返回路线,则会引发Ember数据并错误地指出: Error: assertion failed: Models cannot belong to more than one transaction at a time. 即使我在旧事务上显式调用remove(),并在新事务中添加()(请参见下面的newTransaction()函数): 灰烬数据不再有事务
Error: assertion failed: Models cannot belong to more than one transaction at a time.
即使我在旧事务上显式调用remove(),并在新事务中添加()(请参见下面的newTransaction()函数):
灰烬数据不再有事务,因为灰烬数据的beta版本。因此,这个问题不再相关 如果您仍然遇到这个问题,请您提供一个JSFIDLE?ember数据不再有事务(即使在最新版本的事务中,也可以将模型从一个事务移动到另一个事务)Joachim,您能自己回答吗?Julian:最新的ember数据没有事务,所以这个问题不再有效了……是的,但我想把这个问题从“未回答”列表中去掉,因为我一直在回答:)那么你能不能把它删除,或者自己回答?:)
settingsDetails: Ember.Route.extend({
route: '/details',
transaction: MyApp.store.transaction(),
doBackButton: function() {
var dirty = MyApp.router.get('settingsDetailsController.content.isDirty');
var doTransition = true;
if (dirty) {
var confirmDialog = confirm('You have unsaved changes. Are you sure you want to continue ? \n\nAny chances made will be lost!');
doTransition = confirmDialog;
}
if (doTransition) {
this.doResetSettingsDetails();
MyApp.router.transitionTo('settings.settingsOverview');
}
},
newTransaction: function() {
var oldTransaction = this.get('transaction');
var newTransaction = MyApp.store.transaction();
var record = MyApp.router.get('settingsDetailsController').get('content');
if (record) {
oldTransaction.remove(record);
newTransaction.add(record);
}
this.set('transaction', newTransaction);
},
doUpdateSettingsDetails: function() {
this.get('transaction').commit();
this.newTransaction();
},
doResetSettingsDetails: function() {
this.get('transaction').rollback();
this.newTransaction();
},
connectOutlets: function(router) {
router.get('applicationController').connectOutlet('settingsDetails');
var record = MyApp.store.find(MyApp.PersonDetails, 1);
this.get('transaction').add(record);
router.get('settingsDetailsController').set('content', record);
}
}),