sequelizejs:如何改变回报价值结构?

时间:2017-11-13 20:19:29

标签: node.js sequelize.js

{
    "name": "AA",
    "Category": {
        "id_category": 354,
        "id_parent": 342,
        "position": 0
    }
},
{
    "name": "AAA",
    "Category": {
        "id_category": 355,
        "id_parent": 342,
        "position": 1
    }
},

CategoryLang 属于一个类别,类类别有多个 CategoryLang 。如何更改返回数据,如下所示:

{
    "name": "AA",
        "id_category": 354,
        "id_parent": 342,
        "position": 0

},
{
    "name": "AAA",
    "id_category": 355,
    "id_parent": 342,
    "position": 1
    }
},

转播: 这是我的查询,我使用了 include 函数。也许有另一个关键字可以解决它。但我没有找到它。

  db.Category.findAll(
    {
        attributes: ['id_category','id_parent','position'],
        where: { id_parent:parentId ,active: 1},
        order:'position',
        include : [{
            model:db.CategoryLang,
            where: { id_shop: 1, id_lang: 1 },
            attributes: ['name','description','link_rewrite']
        }]
    }
).then((categories) => {
    return resultReturn.returnFormattedResult(
        res,
        true,
        "Success",
        categories
    );


}).catch((err)=> {
    res.status(400);
    return  resultReturn.returnFormattedResult(
        res,
        false,
        "Can not get Categories"
    );

});

0 个答案:

没有答案