'Alias cannot be inferred
Given the following models, each of the associations work fine in isolation but not if used together. I'm getting:
Error: Alias cannot be inferred: "Employee" has multiple relations with "Person"
Here is the code:
@Table() export default class Employee extends Model {
/** * Selected id of the tester role */ @Column({ field: 'tester_id' }) @ForeignKey(() => Person) public testerId: number;
@BelongsTo(() => Person , { as: 'tester', foreignKey: 'testerId' })
public tester: Person;
/** * Selected id of the Developer role */ @Column({ field: 'developer_id' }) @ForeignKey(() => Person) public developerId: number;
@BelongsTo(() => Person, { as: 'dev', foreignKey: 'developerId' })
public developer: Person;
}
@Table() export default class Person extends Model {
@HasMany(() => Employee , { as: 'tester', foreignKey: 'testerId' }) public tester: Employee[];
@HasMany(() => Employee, { as: 'developer', foreignKey: 'developerId' })
public developer: Employee[];
}
And the error: Error: Alias cannot be inferred: "Employee" has multiple relations with "Person"
can anyone help me?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
