sequelize-typescript
sequelize-typescript copied to clipboard
sequelize with Sequelize.VIRTUAL,
Hi,
is there any way to achieve below in sequelize-typescript ?
const Pug = db.define('pugs', { firstName: { type: Sequelize.STRING, }, lastName: { type: Sequelize.STRING }, fullName: { type: Sequelize.VIRTUAL, get () { return this.getDataValue('firstName') + ' ' + this.getDataValue('lastName') } } })
Thanks
Sure:
import {Table, Column, Model, DataType} from 'sequelize-typescript';
@Table({tableName: 'plugs'})
class Pug extends Model<Pug> {
@Column
firstName: string;
@Column
lastName: string;
@Column(DataType.VIRTUAL)
get fullName() {
return this.getDataValue('firstName') + ' ' + this.getDataValue('lastName');
}
}
Hope this helps!
Thanks for the reply,
But the getDataValue always returning undefined.
"myFullName": "undefined undefined",
Sorry got this, I was not selected firstName and lastName
Thanks