Closed
Description
Assuming the following defined models:
class User extends Model<User> {
companies: Company[];
}
class CompanyUser extends Model<CompanyUser> {
@ForeignKey(() => Company)
@Column
companyId: number;
@ForeignKey(() => User)
@Column
userId: number;
}
@Scopes({bla: {...}})
class Company extends Model<Company> {
users: User[];
}
When selecting entities of a scoped model, the as
value of the include options, that are NOT defined within the scope, is not inferred by sequelize-typescript:
Company
.scope('bla')
.findAll({include: [User]})
.catch(...) // throws "User is not associated to Company!"
;
Current workaround:
Company
.scope('bla')
.findAll({include: [{
model: User,
as: 'users' // <-- this need to be set explicitly
}]})
.catch(...)
;