node.js - Sailsjs Waterline's Query method calls cast function to undefined attributes -
i'm using waterline (postgresql database) method model.query(). example: (the sql query more complicated :) )
model.query('select * user', function(err, result) { });
and there such error:
typeerror: cannot read property 'type' of undefined @ /node_modules/sails-postgresql/lib/query.js:544:33
this code in sails-postgresql module, error occurs:
object.keys(values).foreach(function(key) { // lookup schema type var type = self._schema[key].type; if(!type) return; // attempt parse array if(type === 'array') { try { _values[key] = json.parse(values[key]); } catch(e) { return; } } });
so, i've printed values , keys that
console.log('self._schema[' + key + '] = ' + self._schema[key]);
and found out waterline calls cast function every attruibute of model, there no such attribute used in query. ofcourse causes error. i've made patch:
if(!self._schema[key]) return;
and works fine. don't think right solution.
is there knows how fix bug way? or maybe i'm doing wrong calling query method , should called way?
this happens because model attributes mismatched table fields. go through user model file , make sure attributes matched fields on user table.
Comments
Post a Comment