I'm using Waterline (Postgresql database) method Model.query(). For example: (the sql query is actually much more complicated :) )
Model.query('select * from user', function(err, result) {
});
and there is such error:
TypeError: Cannot read property 'type' of undefined
at /node_modules/sails-postgresql/lib/query.js:544:33
This is the code in the sails-postgresql module, where the error occurs:
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;
}
}
});
So, I've printed the values and keys like that
console.log('self._schema[' + key + '] = ' + self._schema[key]);
and found out that Waterline calls cast function to every attruibute of my Model, even there is no such attribute used in my query. Ofcourse it causes error. I've made a patch:
if(!self._schema[key]) return;
and now it works fine. But I don't think that this is the right solution.
Is there anybody who knows how to fix this bug another way? Or maybe I'm doing wrong calling query method and it should be called another way?