我目前正在使用SQL Server和Sequelize进行项目 . 尝试在具有与之关联的触发器的表中插入行时,我遇到了问题 .
我能够找到有关该问题的信息https://github.com/sequelize/sequelize/issues/3284
我已经下载了.js文件,它说的是它与临时表一起使用来克服这个问题:
SequelizeDatabaseError:如果语句包含没有INTO子句的OUTPUT子句,则DML语句的目标表'tableA'不能具有任何已启用的触发器 .
这个解决方案对我不起作用,在尝试重新使用被交叉的对象并且无法访问所有变量时,我遇到了问题 .
这个问题还有其他的解决方法吗?
这是我的代码:
return Person.create( { lastName: options.lastName,
name: options.name,
}, {transaction: t}).then(
function (person) {
return Student.create({ id :person.id,
numberRecord :'PF-'+person.id,
}, {transaction: t}).then(function (student) {
return Shoots.create({ id : person.id,
numberRecord :'PF-'+person.id
}, {transaction: t}).then(function (record) {
return StudentContract.create({
PersonID :person.id,
dateStart:'2016021 00:00:00.000',
endDate:'20161231 00:00:00.000',}
, {transaction: t}).then(function (contract) {
return student;
});
});
});
});
}).then(function (result) {
// Transaction has been committed
// result is whatever the result of the promise chain returned to the transaction callback is
console.log(result);
cb(null, result);
}).catch(function (err) {
// Transaction has been rolled back
// err is whatever rejected the promise chain returned to the transaction callback is
console.error(+err);
cb(err, "Transaction Failed");
});
使用上面链接中提供的解决方案时,它表示找不到'id'属性 . 'id'在Person和Student中定义为主键 .
来自续集的任何想法或官方解决方案都可以解决这个问题吗?
谢谢!
1 回答
我已经阅读了你的问题,我明白你需要捕捉你插入的内容 . 是的,可以使用表变量捕获插入的数据 .
尝试下面,希望它有助于至少得到一些其他的想法 .
然后,您可以查询Table变量以获取插入的数据 .
谢谢