我有两种模式:
user.js的
module.exports = {
attributes: {
...
profile: {
model: 'Profile'
},
groups: {
collection: 'group',
via: 'users',
dominate: true
},
roles: {
collection: 'role',
via: 'users',
dominate: true
}
}};
和,group.js
module.exports = {
attributes: {
...
users: {
collection: 'user',
via: 'groups'
}
}};
当我尝试将用户添加到一个组时(当我选择一个组并向其添加用户时),它可以正常工作,
var defer = q.defer();
baseDbContext.single(req, 'users')
.then(function(op){
if(!op.status || !op.obj) {
defer.resolve(notFound);
return;
}
op.obj.users = [];
_.each(req.users, function(item){
op.obj.users.add(item);
});
op.obj.save(function(err, obj){
if(err) defer.reject(operationResult().throwException(err));
else defer.resolve(operationResult().succeed());
});
});
return defer.promise;
但是当我尝试向用户添加组时(当我选择用户并向其添加组时)它会无声地失败!!!
var defer = q.defer();
baseDbContext.single(req, 'groups')
.then(function(op){
if(!op.status || !op.obj) {
defer.resolve(notFound);
return;
}
op.obj.groups = [];
_.each(req.groups, function(item){
op.obj.groups.add(item);
});
op.obj.save(function(err, obj){
if(err) defer.reject(operationResult().throwException(err));
else defer.resolve(operationResult().succeed());
});
});
return defer.promise;
当我在sails控制台中检查它时显示:
throw new Error('Unknown rule: ' + ruleName);
Error: Unknown rule: dominate
这是一个简单的多对多插入,为什么会失败? (关于代码的注释,函数baseDbContext.single根据其id找到一个对象,第二个参数用于填充)