Few questions.
I have a user model defined with password and email.
Also it has dynamic property realized trough getters from 1.7 version.
Property is a gravatar link generated based on email.
When I send json data of user to client two things go wrong.
First: Password is included in json data.
Second: gravatar link isn't.
So far I used a work around of defining toJSON in instanceMethods.
Code looks like this
Question is, what is official way to add or hide properties from values/json.
var User = sequelize.define('user',
{
email: {type: Sequelize.STRING, length: 255, allowNull: false, unique: true},
password: {type: Sequelize.STRING, length: 20, allowNull: false}
},
{
getterMethods : {
avatar_link: function ()
{
var hash = ...;
return 'http://www.gravatar.com/avatar/' + hash;
}
},
instanceMethods: {
toJSON: function()
{
var res = this.values;
res.avatar_link = this.avatar_link;
delete res.password;
return res;
}
}
});
So as you see I remove password property and add avatar link property in redefined toJSON.
But its somewhat hacky, may break some things eventually.
So, is there official/better way to handle this?