sequelize create function仅保存少数字段

时间:2017-02-02 16:20:19

标签: sequelize.js

我有以下代码:

socket.on("add_upload", function(upload){
    var data = upload.building_data.data;
    var obj = {
        condo_owner                 : getContent(data,"Condo/Owner"),
        address                         : getContent(data,"Address"),
        state_province          : getContent(data,"State/Province"),
        country                         :   getContent(data,"Country"),
        email                               :   getContent(data,"Email"),
        suite                               :   getContent(data,"Resident Suites"),
        mgt_company                 :   getContent(data, "Mgt. Company"),
        telephone                       : getContent(data,"Telephone"),
        billing_account_no  :   getContent(data,"Billing Account #"),
        billing_count               :   getContent(data,"Billing Count"),
        billing_type                :   getContent(data,"Billing Type"),
        calculation_type        :   getContent(data,"Calculation Type"),
        meter_type                  :   getContent(data,"Meter Type"),
        remittance_type         :   getContent(data, "Remittance Type"),
        city                                : getContent(data, "City"),
        postal_code                 : getContent(data, "Zip/Postal Code")
    };
    console.log(obj);
    Uploads.create(upload.upload).then(function(){
        Buildings.create(obj).then(function(){
            socket.emit("add_upload_successfull");
        });
    });
});

在console.log上它会正确显示所有字段,但是当我使用Create时,它只显示两个保存的字段,因为它应显示保存在数据库中的所有字段。我仔细检查了字段名称,它们是正确的。

1 个答案:

答案 0 :(得分:0)

Uploads.create(upload.upload).then(function(){
    Buildings.create(obj).then(function(){
        socket.emit("add_upload_successfull");
    });
});

这应该使用obj还是upload.building_data?您解决了将数据内容解析为obj的所有问题,然后使用upload.upload调用Uploads.create。我们不知道upload.upload是什么,我们所知道的是您解析的数据来自upload.building_data

我的第一个想法就是将上面的内容改为使用正确的对象:

Uploads.create(obj).then(function(){
    Buildings.create(obj).then(function(){
        socket.emit("add_upload_successfull");
    });
});