Answers for "custom setter in sequelize tutorial"

0

getter and setter sequelize simple way

// method 2
//define 
const User = sequelize.define('user', {
  firstName: DataTypes.TEXT,
  lastName: DataTypes.TEXT,
  fullName: {
    type: DataTypes.VIRTUAL,
    get() {
      return `${this.firstName} ${this.lastName}`;
    },
    set(value) {
      throw new Error('Do not try to set the `fullName` value!');
    }
  }
});

//usage 
const user = await User.create({ firstName: 'John', lastName: 'Doe' });
console.log(user.fullName); // 'John Doe'
Posted by: Guest on December-24-2020

Code answers related to "custom setter in sequelize tutorial"

Code answers related to "Javascript"

Browse Popular Code Answers by Language