Sails.js search by computed property -
i'm writing api in sails.js , have 1 problem finding objects.
i have model attributes:
attributes: { firstname:{ type:"string", required:true, minlength: 2 }, lastname:{ type:"string", required:true, minlength: 2 }, getfullname: function (){ var fl = this.firstname + " " + this.lastname; return fl; }, } and right find object getfullname startswith "xyz qwe"
how can it?
i have tried:
patient.find({ getfullname: { 'startswith': 'tomas' }}).exec(console.log)
and
patient.find({ getfullname(): { 'startswith': 'tomas' }}).exec(console.log)
and both not working.
can access computed property getfullname in find() function?
of course query working:
patient.find({ firstname: { 'startswith': 'tomas' }}).exec(console.log)
exec or callback has 2 arguments (like other callback), it's error , result. code should like.
patient .find({ getfullname: { 'startswith': 'tomas' }}) .exec(function(err, founds){ if(err) return console.error(err); console.log(founds); }); or can use promise chaining did before.
patient .find({ getfullname: { 'startswith': 'tomas' }}) .then(console.log) .catch(console.error);
Comments
Post a Comment