Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 使用Sequelize typescript的关联模型的别名_Node.js_Typescript_Orm_Associations_Sequelize Typescript - Fatal编程技术网

Node.js 使用Sequelize typescript的关联模型的别名

Node.js 使用Sequelize typescript的关联模型的别名,node.js,typescript,orm,associations,sequelize-typescript,Node.js,Typescript,Orm,Associations,Sequelize Typescript,我有两种型号公司和评论。每个公司将有多个审查 这是公司模型 @Table() export class Company extends Model<Company> { @Column({ type: DataType.INTEGER.UNSIGNED, primaryKey: true, autoIncrement: true }) COMPANY_ID: number; @Column({ type: DataType.TEXT }) Name: string

我有两种型号
公司
评论
。每个
公司
将有多个
审查

这是
公司
模型

@Table()
export class Company extends Model<Company> {

  @Column({ type: DataType.INTEGER.UNSIGNED, primaryKey: true, autoIncrement: true })
  COMPANY_ID: number;

  @Column({ type: DataType.TEXT })
  Name: string;

  @HasMany(() => Review)
  reviews: Review[];
}
我正试图获取一家公司所有评论的列表。到目前为止,我写的问题是

    const pagedData = await Review.findAndCountAll({
      attributes: [
        ['REVIEW_ID', 'id'],
        ['Review', 'feedback']
      ],
      include: [{
        model: Company,
        attributes: ['Name']
      }],
      limit,
      offset
    });
我得到的回应是

{
  "total": 2,
  "reviews": [
    {
      "id": 917004723,
      "feedback": "feedback 1",
      "company": {
        "Name": "www.acceleronpharma.com"
      }
    },
    {
      "id": 917004734,
      "feedback": "feedback 2",
      "company": {
        "Name": "http://www.accenture.com"
      }
    }
  ]
}
问题:

  • 是否有方法为关联模型添加别名?比如说,在
    公司中,我希望它是
    companyName
    或者其他什么,而不是
    Name
  • 可以将其作为
    review
    对象本身中的属性拉出,而不是将其作为
    review
    数组中的对象拉出
  • PS:请忽略外壳,我只是添加了一个我所面临问题的例子

    {
      "total": 2,
      "reviews": [
        {
          "id": 917004723,
          "feedback": "feedback 1",
          "company": {
            "Name": "www.acceleronpharma.com"
          }
        },
        {
          "id": 917004734,
          "feedback": "feedback 2",
          "company": {
            "Name": "http://www.accenture.com"
          }
        }
      ]
    }
    
        {
          "id": 917004723,
          "feedback": "feedback 1",
          "companyName": "www.acceleronpharma.com"
        }