How to use an include with attributes with sequelize?

后端 未结 2 1774
执笔经年
执笔经年 2020-12-05 12:33

Any idea how to use an include with attributes (when you need to include only specific fields of the included table) with sequelize?

Currently I have this (but it do

相关标签:
2条回答
  • 2020-12-05 13:21

    Something like this should work

    foo.findAll({
        where      : where,
        attributes : attributes,
        include    : [{ model: bar, attributes: attributes}]
    }).success(function (result) {
    
    0 讨论(0)
  • 2020-12-05 13:23

    We can do something like that for exclude or include specific attribute with sequelize in Node.js.

    Payment.findAll({
        where: {
            DairyId: req.query.dairyid
        },
        attributes: {
            exclude: ['createdAt', 'updatedAt']
        },
        include: {
            model: Customer,
            attributes:['customerName', 'phoneNumber']
        }
    })
    
    0 讨论(0)
提交回复
热议问题