fix(database): fix option-parser include list index (#371)
This commit is contained in:
parent
565249c05c
commit
45d03d3ca5
@ -81,6 +81,7 @@ describe('option parser', () => {
|
|||||||
],
|
],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('with sort option', () => {
|
test('with sort option', () => {
|
||||||
let options: any = {
|
let options: any = {
|
||||||
sort: ['id'],
|
sort: ['id'],
|
||||||
@ -182,4 +183,23 @@ describe('option parser', () => {
|
|||||||
|
|
||||||
expect(params['include'][0]['attributes']['exclude']).toContain('id');
|
expect(params['include'][0]['attributes']['exclude']).toContain('id');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('option parser with multiple association', () => {
|
||||||
|
// fields with association field
|
||||||
|
const options = {
|
||||||
|
appends: ['user', 'comments.id', 'tags.id'],
|
||||||
|
};
|
||||||
|
|
||||||
|
const parser = new OptionsParser(options, {
|
||||||
|
collection: Post,
|
||||||
|
});
|
||||||
|
|
||||||
|
const params = parser.toSequelizeParams();
|
||||||
|
expect(params.include.length).toBe(3);
|
||||||
|
expect(params.include[0].association).toBe('user');
|
||||||
|
expect(params.include[1].association).toBe('comments');
|
||||||
|
expect(params.include[1].attributes).toEqual(['id']);
|
||||||
|
expect(params.include[2].association).toBe('tags');
|
||||||
|
expect(params.include[2].attributes).toEqual(['id']);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -230,7 +230,7 @@ export class OptionsParser {
|
|||||||
association: appendAssociation,
|
association: appendAssociation,
|
||||||
});
|
});
|
||||||
|
|
||||||
existIncludeIndex = 0;
|
existIncludeIndex = queryParams['include'].length - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// end appends
|
// end appends
|
||||||
|
Loading…
Reference in New Issue
Block a user