在sequelize中,可以像这样在一个中创建一行和所有它的关联:
return Product.create({
title: 'Chair',
User: {
first_name: 'Mick',
last_name: 'Broadstone'
}
}, {
include: [ User ]
});
Run Code Online (Sandbox Code Playgroud)
有更新的等价物吗?我试过了
model.user.update(req.body.user, {where: {id: req.user.user_id}, include: [model.profile]})
Run Code Online (Sandbox Code Playgroud)
但它只是更新用户
这样做是为了创造作品
model.user.create(user, {transaction: t, include: [model.profile]})
Run Code Online (Sandbox Code Playgroud) 我想在用户模型上的afterCreate上创建一个sequelize挂钩。当我只创建没有交易的用户时,它的工作效果很好。但是,如果我在事务中运行我的create语句,则挂钩将在提交之前运行。
用户模型挂钩
hooks: {
afterCreate: userModule.NewUserHook,
afterBulkCreate: userModule.NewUserHook
}
Run Code Online (Sandbox Code Playgroud)
挂钩功能
NewUserHook: function NewUserHook(user, options){
console.log('Inside hook');
}
Run Code Online (Sandbox Code Playgroud)
可以在options.transaction中访问该事务。
提交事务后,是否仍要运行挂接?
我懒加载依赖于用户的模块。然后我不想为模块加载的指令声明一个装饰器。但是在尝试装饰指令时,我得到了未知的提供者。
angular.module(moduleName).config(function ($provide) {
var invokeQueue = angular.module(moduleName)._invokeQueue;
invokeQueue.forEach(function (service) {
if(service[1] === 'directive'){
var directive = service[2][0];
$provide.decorator(directive, function ($delegate) {
return $delegate;
})
}
});
});
Run Code Online (Sandbox Code Playgroud)
var 指令是指令名称,正在设置。
错误
[$injector:unpr] 未知提供者:demoDirectiveProvider
如果我更改代码以获取服务或工厂,它会起作用。
以下两个作品
if(service[1] === 'service')
if(service[1] === 'factory')
Run Code Online (Sandbox Code Playgroud)
关于为什么这不适用于指令的任何建议