Can I define a getter of a property as an asyc function in Sequelize?
In the getter I should retrieve a value from another table and I've tried this in the model definition:
...
bio: {
type: Sequelize.STRING,
get: async function() {
let bio = this.getDataValue('bio');
if (bio) {
let bestFriend = await db.models.User.findById(this.getDataValue('BestFriendId'))
if(bestFriend){
bio += ` Best friend: ${bestFriend.name}.`;
}
console.log(bio)
return bio;
} else {
return '';
}
}
},
...
Logging I can read the correct bio with something like:
Born yesterday. Love to read Best friend: Markus
But the object I retrieve has an empty object in the bio attribute.
I suppose that is because the async function is not supported, am I wrong?
How can I achieve this without using an async function?