Skip to content

Model.scope().findAll({...}) cannot infer as in include option #37

Closed
@RobinBuschmann

Description

@RobinBuschmann

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(...)
;

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions