Skip to content

Commit

Permalink
test: fix limit + test in mssql
Browse files Browse the repository at this point in the history
  • Loading branch information
ephys committed Jan 25, 2022
1 parent 1375208 commit 53cca5f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 2 additions & 0 deletions lib/dialects/mssql/query-generator.js
Expand Up @@ -988,6 +988,8 @@ class MSSQLQueryGenerator extends AbstractQueryGenerator {
}

if (options.limit || options.offset) {
// TODO: document why this is adding the primary key of the model in ORDER BY
// if options.include is set
if (!options.order || options.order.length === 0 || options.include && orders.subQueryOrder.length === 0) {
const tablePkFragment = `${this.quoteTable(options.tableAs || model.name)}.${this.quoteIdentifier(model.primaryKeyField)}`;
if (!options.order || options.order.length === 0) {
Expand Down
7 changes: 6 additions & 1 deletion test/support.js
Expand Up @@ -276,7 +276,12 @@ const Support = {
* @returns {string} the SQL string with insignificant whitespace removed.
*/
minifySql(sql) {
return sql.replace(/\s+/g, ' ').trim();
// replace all consecutive whitespaces with a single plain space character
return sql.replace(/\s+/g, ' ')
// remove space before coma
.replace(/ ,/g, ',')
// remove whitespace at start & end
.trim();
},
};

Expand Down
2 changes: 1 addition & 1 deletion test/unit/sql/select.test.js
Expand Up @@ -324,7 +324,7 @@ describe(Support.getTestDialectTeaser('SQL'), () => {
FROM [users] AS [user] LEFT OUTER JOIN [post] AS [POSTS]
ON [user].[id_user] = [POSTS].[user_id]
ORDER BY [user].[last_name] ASC
${sql.addLimitAndOffset({ limit: 30, offset: 10, order: [['`user`.`last_name`', 'ASC']] })};
${sql.addLimitAndOffset({ limit: 30, offset: 10, order: [['last_name', 'ASC']], include }, User)};
`),
});

Expand Down

0 comments on commit 53cca5f

Please sign in to comment.