Node.js Sequelize节点包括模型属性名称别名

Node.js Sequelize节点包括模型属性名称别名,node.js,sequelize.js,Node.js,Sequelize.js,在我的控制器中,我有一个包含的模型国家/地区,它应返回原始数据,即CON.name.CON是包含模型的别名。我想更改列的名称。CON.name到countryName 代码 let include = [{ model: country , all:true }] const Addr = await Address.findAll({ order: [['isDefaultAddress', 'DESC']], where: { Id: parseIn

在我的控制器中,我有一个包含的模型国家/地区,它应返回原始数据,即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"
响应

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']]},

@索拉巴mistry@john,提供数据库中的列名称