Model repository cannot use scopes with included method
Issue
Versions
- sequelize: 6.7.0
- sequelize-typescript: 2.1.1
- typescript: 4.3.5
Issue type
- [x] bug report
- [ ] feature request
Actual behavior
Hi. Im currently studing nest.js framework. And I'm having trouble using sequelize-typescript.
Im use this code snippet as below, and got type error.
const scopes = [
{ method: ['byEmail', body.email] }
];
const user = await this.userModel
.scope(scopes)
.findOne();

But, using scopes with plain text is OK. const scopes = ['byEmail'];
Expected behavior
Scopes should be able to be used with objects with the method.
Steps to reproduce
- Create user model as below
- Create user repository
- Сall the
findOnewith scopes method as above
@Scopes(() => ({
byEmail: (email) => ({
where: { email },
}),
}))
@Table
export class UserEntity extends Model {
@Column({
type: DataType.STRING(255),
})
email: string;
//...some other fields
}
Related code
commit with included bug https://github.com/DustTail/tms-backend/tree/4fbff7ff067415cebdd3457483a1cfa78ec554f4
model: https://github.com/DustTail/tms-backend/blob/4fbff7ff067415cebdd3457483a1cfa78ec554f4/src/models/user.entity.ts controller: https://github.com/DustTail/tms-backend/blob/4fbff7ff067415cebdd3457483a1cfa78ec554f4/src/sessions/sessions.controller.ts#L34
For me its worked when i set array of scopes directly to scope method.
const users = await this.userModel
.scope([
{ method: ['pagination', limit, offset] },
// ... other scopes
]).findAll();