Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

204
Visualizações
Sequelize model with column using references ignores field option

I am not sure if this is a bug or issue with me, but I have this basic model

const { DataTypes } = require('sequelize');


  sequelize.define(
    'Submission',
    {
      id: {
        allowNull: false,
        autoIncrement: true,
        primaryKey: true,
        type: DataTypes.INTEGER,
      },
      widgetId: {
        allowNull: false,
        type: DataTypes.INTEGER,
        references: {
          field: 'widget_id',
          model: {
            tableName: 'widget',
            schema: 'public',
          },
          key: 'id',
        },
        field: 'widget_id',
      },
      createdAt: {
        type: DataTypes.DATE,
        field: 'created_at',
      },
      updatedAt: {
        type: DataTypes.DATE,
        field: 'updated_at',
      },
    },
    {
      tableName: 'submission',
      timestamps: true,
      underscored: true,
    },
  );

and the widget model is identical except the columns/fields and has a id field. I am able to create a widget object / row in our db perfectly fine.

When trying to expand that and create a submission entry at same time as the widget, i expanded things and testing it out by adding the associations and test code as such

  widget.submission = widget.hasOne(submission);
  submission.widget = submission.belongsTo(widget);

  instance.models.Widget.create({
    widgetId: '123456789',
    title: 'test',
    Submission: {
      message: 'test',
    },
  }, {
    include: [{
      association: widget.submission,
    }]
  }).then(r => console.log(r))
    .catch(err => console.log(err));

and I get the following error

ValidationError [SequelizeValidationError]: notNull Violation: Submission.widgetId cannot be null

it seems to ignore my field: 'widget_id and assumes widgetId. The field option seems to work for everything else but this

anyway to handle that? thank you!

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda