Sequelize nodejs包含模型属性名称别名



在我的控制器中,我有一个包含的模型国家/地区,它应该以CON.name.CON是包含模型的别名的形式返回原始数据。我想更改列名称。CON.name到countryName

代码

let include = [{ 
model: country , all:true }]
const Addr = await Address.findAll({
order: [['isDefaultAddress', 'DESC']],
where: {
Id: parseInt(params.req.body.id),
status: 1,
},         
include:include,
raw:true,
attributes:{ exclude: [], include:['con.name']}

响应

CON.createdAt: "2020-04-02T12:35:52.205Z"
CON.id: 1
CON.name: "Afghanistan"
CON.updatedAt: "2020-04-02T12:35:52.205Z"

预期结果

countryCreatedAt: "2020-04-02T12:35:52.205Z"
countryId: 1
countryName: "Afghanistan"
countryUpdatedAt: "2020-04-02T12:35:52.205Z"

以这种方式使用属性

attributes: [['con.id','countryId'],
['con.name', 'countryName'],
['con.createdAt','countryCreatedAt'],
['con.updatedAt','countryUpdatedAt']
] 

我算出的正确答案。。。

attributes: {exclude: [],
include: [[Sequelize.col('con.name'), 'countryName'], 
[Sequelize.col('st.name'), 'stateName']]},

最新更新