我正在使用 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;
现在它工作正常。但我认为这不是正确的解决方案。
有没有人知道如何以另一种方式修复此错误?或者也许我做错了调用查询方法,应该用另一种方式调用它?