I'm still learning to understand NodeJs/SailsJs, sorry if these sound too stupid but I can't seem to search google for a better explanation. I have tried searching for node OOP programming but doesn't seems to explain.
Taking the following query code
Company.findOne({'id':req.param('id')}).then(function(results){
console.log(util.inspect(results, true, null))
})
The output will be
{ id: 1,
companyName: 'Wunly Enterprise1',
createdAt: null,
updatedAt: Wed Jul 08 2015 01:43:19 GMT+0800 (SGT) }
But in SailJs, I can use the following code to update the record
results.name = "change name";
results.save(function(err,newresult){})
Howcome I am able to call save method when I console.log and there are no such method exists??
console.log in NodeJs doesn't print inherited methods (like in chrome, ff...). save is attribute method that every record inherits.
If you want to print all properties of object, you can use this solution https://stackoverflow.com/a/8024294/1334743
just declare function
function getAllPropertyNames( obj ) {
var props = [];
do {
props= props.concat(Object.getOwnPropertyNames( obj ));
} while ( obj = Object.getPrototypeOf( obj ) );
return props;
}
And implement it in your example
Company.findOne({'id':req.param('id')}).then(function(results){
console.log(getAllPropertyNames(result));
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With