Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 在sequelize.js中获取与belongAsmany的关联_Node.js_Typescript_Orm_Sequelize.js - Fatal编程技术网

Node.js 在sequelize.js中获取与belongAsmany的关联

Node.js 在sequelize.js中获取与belongAsmany的关联,node.js,typescript,orm,sequelize.js,Node.js,Typescript,Orm,Sequelize.js,我通过UserDevice联接表在用户和设备模型之间建立了多对多关系: device.belongsToMany(user, { through: { model: userDevice }, foreignKey: "deviceId", as: "customers" }); user.belongsToMany(device, { through: {

我通过UserDevice联接表在用户和设备模型之间建立了多对多关系:

    device.belongsToMany(user, {
        through: {
            model: userDevice
        },
        foreignKey: "deviceId",
        as: "customers"
    });

    user.belongsToMany(device, {
        through: {
            model: userDevice
        },
        foreignKey: "customerId",
        as: "devices"
    });

    setCustomers: Sequelize.BelongsToManySetAssociationsMixin<UserInstance, string, UserDeviceAttribute>;
    getCustomers: Sequelize.BelongsToManyGetAssociationsMixin<UserInstance>;
我不知道如何在其他场景中填充客户,即当我手动设置客户时。现在,我正在尝试类似于:

        return device.setCustomers(customers)
        .then(() => {
            return device.getCustomers();
        })
        .then((users) => {
            device.setAttributes("customers", users);
            return device;
        });

但它不起作用,setAttributes不设置customers字段。

答案在问题中。我今天遇到同样的问题时发现了这个bug。

setAttributes似乎是sequelize的保留方法

        return device.setCustomers(customers)
        .then(() => {
            return device.getCustomers();
        })
        .then((users) => {
            device.setAttributes("customers", users);
            return device;
        });