Adding default value to non selected attribute of a model
When I want to select specific attribute from my model it is returning not related attributes. My function for selecting is this async findOneLogIn(username: string): Promise<EmployeeModel | null> { return this.model.findOne({ where: { [Op.or]: [ { username: { [Op.iLike]: username } }, { email: { [Op.iLike]: username } } ], isBlocked: false, type: { [Op.in]: [ EmployeeTypeEnum.EMPLOYEE, EmployeeTypeEnum.INTERN ] } }, attributes: ['id'], include: [ { model: JobModel, as: 'job', attributes: ['shortName'] }, { model: CompanyModel, as: 'company', attributes: [ 'uuid', 'fileTypes', 'uploadLimitMb', 'defaultLanguage' ] } ] }); } And My model is this @Table({ tableName: 'employees', modelName: 'EmployeeModel', paranoid: true, underscored: true }) export class EmployeeModel extends SequelizeModelHelper { @Column({ type: DataType.STRING, allowNull: true, field: 'specode1' }) specode1: string;
@Column({
type: DataType.STRING,
allowNull: true,
field: 'specode2'
})
specode2: string;
@Column({
type: DataType.STRING,
allowNull: true,
field: 'specode3'
})
specode3: string;
@Column({
type: DataType.STRING,
allowNull: true,
field: 'specode4'
})
specode4: string;
@Column({
type: DataType.STRING,
allowNull: true,
field: 'specode5'
})
specode5: string;
@Column({
type: DataType.STRING,
allowNull: true,
field: 'name'
})
name: string;
@Column({
type: DataType.VIRTUAL,
get() {
// eslint-disable-next-line
let fullName = `${(this as EmployeeModel).name} ${(this as EmployeeModel).surname}`;
}
})
fullName: string;
@Column({
type: DataType.STRING,
allowNull: false,
field: 'surname'
})
surname: string;
@Column({
type: DataType.STRING,
allowNull: true,
field: 'email'
})
email: string;
@Column({
type: DataType.DATEONLY,
allowNull: false,
field: 'birth_date'
})
birthDate: string;
@Column({
type: DataType.STRING,
allowNull: false,
field: 'username'
})
username: string;
@Column({
type: DataType.STRING,
allowNull: false,
field: 'password'
})
password: string;
@Column({
field: 'status',
type: DataType.ENUM(
EmployeeStatusEnum.OFFLINE,
EmployeeStatusEnum.ONLINE
),
allowNull: false
})
status: EmployeeStatusEnum;
@Column({
field: 'week_start_day',
type: DataType.INTEGER,
defaultValue: 1
})
weekStartDay: number;
@Column({
field: 'joined_at',
type: DataType.DATEONLY,
allowNull: false,
defaultValue: new Date()
})
joinedAt: string;
@Column({
field: 'datetime_style',
type: DataType.STRING,
defaultValue: 'DD.MM.YYYY HH:mm'
})
dateTimeStyle: string;
@Column({
field: 'last_active_time',
type: DataType.DATE,
allowNull: true
})
lastActiveTime: string;
@Column({
field: 'used_storage',
type: DataType.INTEGER,
allowNull: false,
defaultValue: 0
})
usedStorage: number;
@ForeignKey(() => EmployeeModel)
@Column({
field: 'manager_id',
type: DataType.NUMBER,
allowNull: true
})
managerId: number;
@Column({
field: 'shift_id',
type: DataType.NUMBER,
allowNull: true
})
shiftId: number;
@ForeignKey(() => JobModel)
@Column({
field: 'job_id',
type: DataType.NUMBER,
allowNull: true
})
jobId: number;
@Column({
field: 'department_id',
type: DataType.NUMBER,
allowNull: true
})
departmentId: number;
@Column({
field: 'division_id',
type: DataType.NUMBER,
allowNull: true
})
divisionId: number;
@ForeignKey(() => CompanyModel)
@Column({
field: 'company_id',
type: DataType.NUMBER,
allowNull: true
})
companyId: number;
@Column({
field: 'education_level_id',
type: DataType.NUMBER,
allowNull: true
})
educationLevelId: number;
@BelongsTo(() => JobModel, {
foreignKey: 'jobId',
targetKey: 'id',
as: 'job'
})
job: JobModel;
constructor(entity?: Partial<EmployeeModel>) {
super();
Object.assign(this, entity);
}
} and the result of this query is