Answer the question
In order to leave comments, you need to log in
Why, when requesting data through Sequelize, an error is generated that you need to specify an alias?
I use:
"sequelize": "^6.6.5",
"sequelize-typescript": "^2.1.0",
There is a company data model, which can be a child of another company and, accordingly, there is:
@ForeignKey(() => Company)
@Column({
type: DataType.INTEGER
})
parentId: number;
@BelongsTo(() => Company, "parentId")
parent: Company;
@HasMany(() => Company, "parentId")
subsidiaries: Company[];
"parentId": {
"onDelete": "NO ACTION",
"onUpdate": "CASCADE",
"references": {
"model": "companies",
"key": "id"
},
"allowNull": true,
"type": Sequelize.INTEGER
},
const company = await Company.findByPk(companyId, { include: [{ model: Company, as: "parentId" }] });
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question