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!