Skip to content

Commit eba46f2

Browse files
Merge pull request #126 from IzikLisbon/master
When `IFindOptions.include = []` the `where` clause is ignored
2 parents fe489ec + 87aaf65 commit eba46f2

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

lib/services/models.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ export function inferAlias(options: any, source: any): any {
249249
options.include = [options.include];
250250
} else if (!options.include.length) {
251251
delete options.include;
252-
return;
252+
return options;
253253
}
254254

255255
// convert all included elements to { model: Model } form

test/specs/model.spec.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,36 @@ describe('model', () => {
900900
expect(u.username).to.equal('A fancy name');
901901
});
902902
});
903+
904+
it('should filter based on the where clause even if IFindOptions.include is []', () => {
905+
@Table({paranoid: true, timestamps: true})
906+
class User extends Model<User> {
907+
908+
@Column
909+
username: string;
910+
}
911+
sequelize.addModels([User]);
912+
913+
return User.sync({force: true})
914+
.then(() => {
915+
return User.create({username: 'a1'});
916+
})
917+
.then(() => {
918+
return User.create({username: 'a2'});
919+
})
920+
.then(() => {
921+
return User.findOne<User>({where: {username: 'a2'}, include: []});
922+
})
923+
.then((u) => {
924+
expect(u.username).to.equal('a2');
925+
})
926+
.then(() => {
927+
return User.findOne<User>({where: {username: 'a1'}, include: []});
928+
})
929+
.then((u) => {
930+
expect(u.username).to.equal('a1');
931+
})
932+
});
903933
});
904934

905935
describe('findOrInitialize', () => {

0 commit comments

Comments
 (0)