Alias cannot be inferred
See original GitHub issueGiven the following models, each of the associations work fine in isolation but not if used together. I’m getting:
Error: Alias cannot be inferred: “Estimate” has multiple relations with “Employee”
What am I doing wrong?
@Table()
export default class Estimate extends Model<Estimate> {
// Fields....
@ForeignKey(() => Employee) @Column estimatorId: number;
@BelongsTo(() => Employee) estimator: Employee;
@ForeignKey(() => Employee) @Column foremanId: number;
@BelongsTo(() => Employee) foreman: Employee;
@BelongsToMany(() => Employee, () => Crew) crew: Employee[];
}
@Table()
export default class Employee extends Model<Employee> {
// Fields....
@HasMany(() => Estimate, 'estimatorId') estimatesAsEstimator: Estimate[];
@HasMany(() => Estimate, 'foremanId') estimatesAsForeman: Estimate[];
@BelongsToMany(() => Estimate, () => Crew) estimatesAsCrew: Estimate[];
}
@Table()
export default class Crew extends Model<Crew> {
@ForeignKey(() => Employee) @Column employeeId: number;
@ForeignKey(() => Estimate) @Column estimateId: number;
}
Issue Analytics
- State:
- Created 6 years ago
- Comments:22 (12 by maintainers)
Top Results From Across the Web
Alias cannot be inferred · Issue #327 - GitHub
I'm getting: Error: Alias cannot be inferred: "Estimate" has multiple relations with "Employee" What am I doing wrong? @Table() export ...
Read more >Alias for the associated models using Sequelize typescript
Is there a way to add an alias for the associated model? Like instead of Name in the Company I would want it...
Read more >Type Aliases vs Interfaces in TypeScript - DEV Community
Like variables, you can't declare the same type alias more than once. Aliases are also never inferred by TypeScript, you have to explicitly ......
Read more >Common issues and solutions - mypy 0.991 documentation
The reason is that if the type of a is unknown, the type of a.split() is also unknown, so it is inferred as...
Read more >Aliases | Elasticsearch Guide [8.5] | Elastic
An alias cannot point to both data streams and indices. You also cannot add a data stream's backing index to an index alias....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@doovers Does the error happen while initializing these models or when trying to retrieve data? If it happens when retrieving data, you also need to define what exact
include
do you want to use. Therefor you have to setas
explicitly like:@RobinBuschmann Apologies for the late reply! I had another look at this and it happens when I call
create
on a model thatBelongsTo
a model withinclude: [{ all: true }]
Logging
include
at/node_modules/sequelize/lib/model.js:465:29
yields:Note that the model attribute is missing where
all: true
but in the parent it is present.