Validate "sequelize" column of one model based on other column in different model

Viewed 177

I have two models let's say "Person" which has first_name, last_name columns. The second one would be "Student" which has other properties. I want to validate that if a new Student is created, then "first_name" is not null. But I want to do that when I define the model. is That possible?

const Student = sequelize.define("student", {
    id: {
      allowNull: false,
      primaryKey: true,
      type: DataTypes.UUID,
      defaultValue: DataTypes.UUIDV4,
      validate: {
        isValid() {
          //here I want to validate if Person.first_name is not null, and if it is I want to throw new Error.
        }
      }
    },
}

Thanks for your help.

0 Answers
Related