sequelize validation error during save nested model

Viewed 13

I am using nestjs with Sequelize orm, and I cannot save the parent object(which is the "item") with its relations([relation1, relation2]) and throw validation error with no message, how can I fix this or what is the best way to create a model instance associated with the built model instance (template1&2 ,relatation1&2 in this case)

const template1 = this.sequelize.getRepository(TemplateModel).build(
      {
        name: 'tem_1',
        json: "some json",
      }
    );

const template2 = this.sequelize.getRepository(TemplateModel).build(
      {
        name: 'tem_2',
        json: "some json",
      }
    );

 const relation1 = this.sequelize
      .getRepository(ItemRelationModel)
      .build(
        {
          template: template1,
        },
        { include: { all: true, nested: true } },
      );

    const relation2 = this.sequelize
      .getRepository(ExamItemFormRelationModel)
      .build(
        {
          masterRelationId: relation1.id,
          template: template2,
        },
        {
          include: { all: true, nested: true },
        },
      );

    const item = this.sequelize.getRepository(ItemModel).build(
      {
        name: 'ItemName_1',
        relations: [relation1, relation2],
      },
      { include: { all: true, nested: true } },
    );
0 Answers
Related