序列化:未处理的拒绝错误:不能同时设置“替换”和“绑定”

时间:2019-05-24 15:52:18

标签: node.js angular express sequelize.js

仅在POST(创建)请求中的Sequelize(EXPRESS上的REST API)中,我从使用的控制器中调用API Route,该API调用该函数:使用关联,模型+关联+路由创建实例看起来不错,但出现错误:

错误:replacementsbind不能同时设置

我无法解决这个问题,但是花了很多时间解决这个错误。

请有人帮我吗?

我尝试过:

具有异步返回结果的中间件错误处理程序。

删除“ freezeTableName”,未做任何更改。

config.js:

const AddressModel = require('../model/address.model');
const CompanyModel = require('../model/company.model');

const Address = AddressModel(sequelize, Sequelize);
const Company = CompanyModel(sequelize, Sequelize);

Company.belongsTo(Address);

....

router.js:

module.exports = function (app) {

    let company = require('../controllers/company.controller.js');

    // Create a new Customer
    app.post('/api/company', company.createCompany);

....


company.controller.js:

const db = require('../config/db.config.js');
const Company = db.Company;
const Address = db.Address;

// Post a Company
exports.createCompany = async (req, res) => {
    const transaction = await db.sequelize.transaction();
    try {
        let company = await Company.create({
            name: req.body.name,
            Address: {
                whole_address: 'TEST ADDRESS FIELD',
                ruian_adm_code: 126252
            }
        }, {
            include: [Address],
            transaction
        });
        await transaction.commit();
        if (company) {
            res.json({
                success: 1,
                data: company,
                message: 'Company created.'
            });
        }
    } catch (ex) {
        await transaction.rollback();
        res.json({success: 0, message: ex});
    }
};

....

返回=错误:replacementsbind不能同时设置

0 个答案:

没有答案