Answer the question
In order to leave comments, you need to log in
How to display a virtual field?
I'm trying to display a virtual field, what am I doing wrong?
const news = sequelize.define('news', {
id: {
type: Sequelize.INTEGER,
autoIncrement: true,
primaryKey: true,
allowNull: false
},
title: {
type: Sequelize.STRING,
allowNull: false
},
content: {
type: Sequelize.TEXT,
allowNull: false
},
userId: {
type: Sequelize.INTEGER,
allowNull: false
},
date: {
type: Sequelize.DATE,
allowNull: false
},
reduct: {
type: Sequelize.VIRTUAL,
get: function() {
return `${ this.content.slice(0,50) }`;
}
}
},{
timestamps: false,
freezeTableName: true
});
news.findAll({raw: true, offset: offset, limit: limit, order: , include: {
model: models.db.user,
attributes: ['id', 'login']
}})
.then(news=>{
response.json(news)
})
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question