I want to add additional properties to my object, before I return it to the client. At they moment they are omitted from the object when it is serialized. Is there are way to add a transient property?
I think setting type to DataTypes.VIRTUAL may help.
For example
var Line = sequelize.define("Line", {
name: {
type: DataTypes.STRING(50),
allowNull: false
},
projects: {
type: DataTypes.VIRTUAL
}
});
Line.findAll().then(function (lines) {
for (var i = 0; i < lines.length; i++)
lines[i].projects = [];
console.log(JSON.stringify(lines));
});
Output
[{"name":"test1","projects":[]},{"name":"test2","projects":[]}]
Documentation: http://docs.sequelizejs.com/en/latest/api/datatypes/
Hope it helps.
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