【发布时间】:2015-02-17 00:53:12
【问题描述】:
我正在尝试在表中创建一条记录,它与其他现有模型共享一些属性。
// model:
module.exports = {
attributes: {
...
contentType: 'string', // This is a combination foreign-key,
// which is not currently
content: 'number', // supported in waterline
...
}
}
// creating code:
sails.log('item.content:', typeof item.content, item.content);
UserContentLibrary.create({
user: prodSubscription.user,
productContentSubscription: pcs.id,
contentType: item.contentType,
content: item.content,
}, function uclCreateCB(err, ucl){
if (err){
sails.log.error(err);
}
itemDone();
});
// error (console output):
debug: item.content: number 3
error: Error (E_VALIDATION) :: 1 attribute is invalid
...
Invalid attributes sent to UserContentLibrary:
content
`undefined` should be a number (instead of "30", which is a string)
从调试日志中可以看出,item.content 确实是一个数字,但是由于某种原因,它在某个地方(可能是适配器)被转换为字符串。我该如何解决这个问题?
【问题讨论】:
-
如果你先做
parseInt(content)呢? -
你有任何回调在运行吗?因为它不仅仅是将其设为字符串,而是将其设为 30 而不是 3。您可能需要运行 node-debugger 并查找数字更改的位置。