Sail 多对多关联在添加关联对象后在保存时抛出错误。这是我的建模。
User:
module.exports = {
attributes: {
...
operations: {
collection: 'operation',
via: 'users'
}
}
};
操作:
module.exports = {
attributes: {
...
users: {
collection: 'users',
via: 'operations',
}
}
};
在我的用户控制器上,我有:
addPermissionToUsers: function(req, res) {
Users.findOne(2).populate('operations').exec(function (err, user) {
if (err) throw err// handle error
// Queue up a record to be inserted into the join table
user.operations.add(1);
Save the user, creating the new associations in the join table
user.save(function (err) {
if (err) throw err
res.json(user)
});
});
}
这是错误跟踪:
if (err) throw err
^
Error (E_UNKNOWN) :: Encountered an unexpected error
at new WLError (/usr/local/lib/node_modules/sails/node_modules/waterline/lib/waterline/error/WLError.js:25:15)
at /usr/local/lib/node_modules/sails/node_modules/waterline/lib/waterline/model/lib/defaultMethods/save.js:188:17
at /usr/local/lib/node_modules/sails/node_modules/waterline/node_modules/async/lib/async.js:52:16
at /usr/local/lib/node_modules/sails/node_modules/waterline/node_modules/async/lib/async.js:550:17
at /usr/local/lib/node_modules/sails/node_modules/waterline/node_modules/async/lib/async.js:544:17
at _arrayEach (/usr/local/lib/node_modules/sails/node_modules/waterline/node_modules/async/lib/async.js:85