Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

210
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda