You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a model. And Added Hooks Before Save and After Create They Are both not instantiating uuid of my AccessModel.
import {
Column,
DataType,
BelongsTo,
Table,
BeforeCreate,
BeforeValidate,
AfterCreate,
BeforeSave
} from 'sequelize-typescript';
import { SequelizeModelHelper } from 'src/common/helpers';
import { AccessInterface } from 'src/modules/companies/managements/staffs/employees/accesses/interfaces';
import { v4 } from 'uuid';
import { AccessModelDto, CreateAccessModelDto } from '../dto'; @table({
tableName: 'accesses',
modelName: 'AccessModel'
})
export class AccessModel extends SequelizeModelHelper { @column({
field: 'title',
type: DataType.STRING
// //defaultValue: ''
})
title: string;
You need to explicitly define your uuid field something like this:
uuid: {type: DataTypes.UUID,defaultValue: DataTypes.UUIDV4,// you should use "defaultValue: UUDV4" instead if your database doesn't have native UUID supportprimaryKey: true,allowNull: false,},
If you set up your uuid field to use UUDV4 as the default value, I'm not sure if you'd still need this @BeforeSave hook as Sequelize will automatically generate a UUID if one isn't provided when creating a new instance.
No that is not the case if i attach default property to the column decorator after receiving entity record from database, in a case when don't select uuid attribute it will define uuid property to the entity
I have a model. And Added Hooks Before Save and After Create They Are both not instantiating uuid of my AccessModel.
import {
Column,
DataType,
BelongsTo,
Table,
BeforeCreate,
BeforeValidate,
AfterCreate,
BeforeSave
} from 'sequelize-typescript';
import { SequelizeModelHelper } from 'src/common/helpers';
import { AccessInterface } from 'src/modules/companies/managements/staffs/employees/accesses/interfaces';
import { v4 } from 'uuid';
import { AccessModelDto, CreateAccessModelDto } from '../dto';
@table({
tableName: 'accesses',
modelName: 'AccessModel'
})
export class AccessModel extends SequelizeModelHelper {
@column({
field: 'title',
type: DataType.STRING
// //defaultValue: ''
})
title: string;
}
And The Error is SequelizeValidationError: notNull Violation: AccessModel.uuid cannot be null
The text was updated successfully, but these errors were encountered: