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
数组中的对象拉出{
"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"
}