你說得對,目前沒有交易支持。您的問題實際上聽起來像你正在做的事情,如:
sequelize.query('UPDATE mytable SET expired=0').success(function() {
Mytable.findAll(/* conditions */).success(function(entries) {
entries.forEach(function(entry){ entries.updateAttributes({expired:1}) })
Mytable.findAll().success(function(entries){
// check status of entries
})
})
})
此代碼更新某些條目,但不等待它完成。如果你有這樣的事情,你應該使用QueryChainer,就像這樣:
var chainer = new Sequelize.Utils.QueryChainer
entries.forEach(function(entry) {
chainer.add(entry.updateAttributes({ expired: 1 }))
})
chainer.run().success(function() {
// now go on here
})
如果不具備上述錯誤並想先收集所有的操作,之後批量執行這些(和串行)做到這一點:
var chainer = new Sequelize.Utils.QueryChainer
entries.forEach(function(entry) {
chainer.add(entry, 'updateAttributes', [{ expired: 1 }])
})
chainer.runSerially().success(function() {
// now go on here
})
希望幫助
不會使它不可能的'SELECT'得到數據,而QueryChainer工作? – Hubro 2012-01-27 19:53:07
爲了澄清,我擔心,因爲每個'UPDATE'分開運行,'SELECT'查詢可能會在更新查詢之間得到一些錯誤的數據 – Hubro 2012-01-27 20:09:16
您能澄清一下嗎? QueryChainer中的所有操作是按順序但分開執行的,還是實際上是作爲一個查詢執行的?我只是不希望'SELECT'語句能夠在QueryChainer運行時獲取數據**,從而得到不正確的數據。 – Hubro 2012-01-28 19:08:47