首页 > 解决方案 > 在 sequelize-typescript 中涉及另一个字段来设置功能

问题描述

问题是我无法访问其他不同类型的字段。在注释列中,set 函数可以访问 name 列但无法访问 num 列并在我尝试记录或使用 setDataValue 时给出未定义。有什么解决方案吗?

 @Column({
    type: DataType.STRING,
    allowNull: false,
  })
  name: string;

  @Column({
    type: DataType.INTEGER,
    allowNull: false,
  })
  num: number;

  @Column({
    type: DataType.STRING,
    allowNull: false,
  })

  set comment(value: string) {
    console.log(this.name);
    console.log(this.num);
    console.log(this.getDataValue('name'));
    console.log(this.getDataValue('num'));
    this.setDataValue('comment', value + this.name);
  }

这是控制台输出:test123, undefined, test123, undefined,

标签: sequelize.jssequelize-typescript

解决方案


推荐阅读