json - NodeJs Sequelize removing properties in toJSON method leads to removed value from model itself -
i have sequelizeinstance object need omit values when change json whenever call delete, deletes value sequelizeinstance well. here code below:
instancemethods: { tojson: function() { var values = this.get(); delete values.password; delete values.salt; return values; } }
the issue i'm facing whenever called tojson(), sequelizeinstance have removed values password , salt. possible solution can do shallow copy of object , return instead. i'm wondering there other better ways approach issue.
what doing create method called .publicdata
this
instancemethods: { publicdata: function () { return { name: this.name, publicfield: this.publicfield // not add private fields here } } }
it perform copy containing wanted fields. approach because don't have worry updating code every time add new private property because wont included public data default, have manually white list them see approach security measure too
Comments
Post a Comment