diff --git a/lib/sqlTranslator.js b/lib/sqlTranslator.js index 7612c56..725e0b9 100644 --- a/lib/sqlTranslator.js +++ b/lib/sqlTranslator.js @@ -902,7 +902,7 @@ class SqlTranslator { const projText = 'count(1) cnt'; const { stmt: filterText } = this.translateFilter(entity, filter, aliasDict, filterRefAlias, currentNumber, option); if (count && count > 0) { - const subQuerySql = this.populateSelectStmt('1', fromText, aliasDict, filterText, undefined, undefined, undefined, undefined, option, Object.assign({}, selection, { indexFrom: 0, count })); + const subQuerySql = this.populateSelectStmt('1', fromText, aliasDict, filterText, undefined, undefined, 0, count, option, Object.assign({}, selection, { indexFrom: 0, count })); return `select count(1) cnt from (${subQuerySql}) __tmp`; } return this.populateSelectStmt(projText, fromText, aliasDict, filterText, undefined, undefined, undefined, undefined, option, selection); diff --git a/src/sqlTranslator.ts b/src/sqlTranslator.ts index 0c8a606..af5880a 100644 --- a/src/sqlTranslator.ts +++ b/src/sqlTranslator.ts @@ -1119,7 +1119,7 @@ export abstract class SqlTranslator { const { stmt: filterText } = this.translateFilter(entity, filter, aliasDict, filterRefAlias, currentNumber, option); if (count && count > 0) { - const subQuerySql = this.populateSelectStmt('1', fromText, aliasDict, filterText, undefined, undefined, undefined, undefined, option, Object.assign({}, selection, { indexFrom: 0, count }) as ED[T]['Selection']); + const subQuerySql = this.populateSelectStmt('1', fromText, aliasDict, filterText, undefined, undefined, 0, count, option, Object.assign({}, selection, { indexFrom: 0, count }) as ED[T]['Selection']); return `select count(1) cnt from (${subQuerySql}) __tmp`; } return this.populateSelectStmt(projText, fromText, aliasDict, filterText, undefined, undefined, undefined, undefined, option, selection as ED[T]['Selection']); diff --git a/test/testMySQLStore.ts b/test/testMySQLStore.ts index fcf3ec3..a7b81f7 100644 --- a/test/testMySQLStore.ts +++ b/test/testMySQLStore.ts @@ -1467,7 +1467,6 @@ describe('test mysqlstore', function () { } }, context, {}); - process.env.NODE_ENV = 'development'; const row = await store.select('oper', { data: { id: 1, @@ -1488,8 +1487,35 @@ describe('test mysqlstore', function () { } }, context, {}); + process.env.NODE_ENV = 'development'; + const row2 = await store.select('oper', { + data: { + id: 1, + data: { + name: 1, + price: 1, + }, + }, + filter: { + id, + data: { + '.$or': [ + { + name: 'xc', + }, + { + name: { + '.$includes': 'xc', + } + } + ], + }, + } + }, context, {}); + await context.commit(); assert(row.length === 1); + assert(row2.length === 1); }); it('[1.12]complicated json filter', async () => {