Я пытаюсь обновить таблицу соединений.
Моя таблица productInput
была обновлена, но моя productInputValue
нет. Я продолжаю получать сообщение терминала TypeError: input.createProductInput is not a function
Это то, что я пытался
Вот моя модель
module.exports = (sequelize, DataTypes) => {
const ProductInput = sequelize.define('productInput', {
id: {
type: DataTypes.INTEGER,
allowNull: false,
primaryKey: true,
autoIncrement: true,
field: 'id'
},
productCode: {
type: DataTypes.STRING,
allowNull: false,
field: 'productCode'
},
input: {
type: DataTypes.STRING,
allowNull: false,
field: 'input'
},
required: {
type: DataTypes.BOOLEAN,
allowNull: false,
field: 'required'
},
deleted: {
type: DataTypes.BOOLEAN,
allowNull: false,
field: 'deleted'
}
}, {
timestamps: false,
tableName: 'productInput'
});
ProductInput.associate = function (models) {
// Input have many values
ProductInput.hasMany(models.productInputValue)
};
return ProductInput;
};
module.exports = function(sequelize, DataTypes) {
const ProductInputValue = sequelize.define('productInputValue', {
inputId: {
type: DataTypes.INTEGER,
allowNull: false,
references: {
model: 'productInput',
key: 'id'
},
field: 'inputId'
},
value: {
type: DataTypes.STRING,
allowNull: false,
field: 'value'
},
id: {
type: DataTypes.INTEGER,
allowNull: false,
primaryKey: true,
autoIncrement: true,
field: 'id'
},
deleted: {
type: DataTypes.BOOLEAN,
allowNull: false,
field: 'deleted'
}
}, {
timestamps: false,
tableName: 'productInputValue'
});
ProductInputValue.associate = function (models) {
// Values belong to Input
ProductInputValue.belongsTo(models.productInput)
};
return ProductInputValue;
};
Вот основная массаСоздать
let newInputs = inputs.map(async (input) => {
console.log(`Here are our inputs`, JSON.stringify(input));
await productInput.create({
productCode: productCode,
input: input.inputName,
required: input.required,
deleted: input.deleted,
value: input.values,
}).then(async (result) => {
console.log(`Result: `, JSON.stringify(result, null, '\t'));
console.log(`Discovery Source`,JSON.stringify(req.body, null, '\t'));
await result.createProductInputValue({
value: result.values
})
}
).then(results => {
console.log(`worked`)
}).catch(err =>
console.log(JSON.stringify(err, null, '\t')))
});
Я зарегистрировал свои модели в консоли, чтобы проверить сгенерированные методы, и получил функции «createProductInputValue». Когда я пытаюсь использовать функцию, она заявляет, что функция не существует. Любая помощь?