Skip to content
Permalink
Browse files

fix(QueryBuilder): Ignore orders in aggregate queries

  • Loading branch information
elpete committed Feb 28, 2020
1 parent 0fbe206 commit 39e1338a147838165e05225bd91ef7e6cde2319a
Showing with 17 additions and 0 deletions.
  1. +3 −0 models/Query/QueryBuilder.cfc
  2. +14 −0 tests/specs/Query/Abstract/QueryExecutionSpec.cfc
@@ -2490,9 +2490,12 @@ component displayname="QueryBuilder" accessors="true" {
*/
private function withAggregate( required struct aggregate, required any callback ) {
var originalAggregate = getAggregate();
var originalOrders = getOrders();
setAggregate( arguments.aggregate );
setOrders( [] );
var result = callback();
setAggregate( originalAggregate );
setOrders( originalOrders );
return result;
}

@@ -461,6 +461,20 @@ component extends="testbox.system.BaseSpec" {
expect( builder.getColumns() ).toBe( [ "id", "name" ] );
} );

it( "ignores orders in the aggregate query and sets them back afterward", function() {
var builder = getBuilder();
var expectedQuery = queryNew( "aggregate", "integer", [ { aggregate: 1 } ] );
builder
.$( "runQuery" )
.$args( sql = "SELECT COUNT(*) AS ""aggregate"" FROM ""users""", options = {} )
.$results( expectedQuery );

builder.from( "users" ).orderBy( "name" );
builder.from( "users" ).count();

expect( builder.getOrders() ).toBe( [ { "column": "name", "direction": "asc" } ] );
} );

it( "should clear out the aggregate properties after an aggregate has been executed", function() {
var builder = getBuilder();
var expectedQuery = queryNew( "aggregate", "integer", [ { aggregate: 1 } ] );

0 comments on commit 39e1338

Please sign in to comment.
You can’t perform that action at this time.