【发布时间】:2014-05-28 13:59:35
【问题描述】:
我正在使用 Waterline(Postgresql 数据库)方法 Model.query()。 例如:(sql查询实际上要复杂得多:))
Model.query('select * from user', function(err, result) {
});
还有这样的错误:
TypeError: Cannot read property 'type' of undefined
at /node_modules/sails-postgresql/lib/query.js:544:33
这是sails-postgresql模块中出现错误的代码:
Object.keys(values).forEach(function(key) {
// Lookup schema type
var type = self._schema[key].type;
if(!type) return;
// Attempt to parse Array
if(type === 'array') {
try {
_values[key] = JSON.parse(values[key]);
} catch(e) {
return;
}
}
});
所以,我已经打印了类似的值和键
console.log('self._schema[' + key + '] = ' + self._schema[key]);
发现 Waterline 对我的模型的每个属性都调用了强制转换函数,即使我的查询中没有使用这样的属性。当然会导致错误。 我做了一个补丁:
if(!self._schema[key]) return;
现在它工作正常。但我认为这不是正确的解决方案。
有谁知道如何以另一种方式修复此错误? 或者我调用查询方法的方法有误,应该以另一种方式调用?
【问题讨论】:
标签: node.js postgresql sails.js waterline