N
N
narem2021-12-04 16:50:13
Node.js
narem, 2021-12-04 16:50:13

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)
    })

Also tried get() {
return `${ this.content.slice(0,50) }`;
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question