gpt4 book ai didi

transactions - Ember 交易 : Moving objects between transactions

转载 作者:行者123 更新时间:2023-12-02 05:15:08 28 4
gpt4 key购买 nike

我已经实现了一个具有事务的路由。当用户通过单击“后退”按钮移出这条路线时,我希望用户能够确认退出并丢失通过回滚事务所做的任何更改。

问题是,如果用户返回路由,Ember Data 会引发错误并指出:

Error: assertion failed: Models cannot belong to more than one transaction at a time.

即使我在旧事务上显式调用 remove() 并将 add() 添加到新事务中也是如此(请参阅下面的 newTransaction() 函数):
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);
}
}),

最佳答案

Ember Data 不再有交易,因为 Ember Data 的测试版。因此,这个问题不再相关。

关于transactions - Ember 交易 : Moving objects between transactions,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12299157/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com